Answer the question
In order to leave comments, you need to log in
Buttons do not respond to calls. What could be wrong?
Good afternoon!
Tell me, please.
I create application of type "test".
I have a menu on the main page.
Created tests and I'm trying to connect them to the menu.
Those. press the button and go to the test.
But the app doesn't move.
Android also does not show errors.
The transition just doesn't work.
Can someone suggest what could be the issue.
Here is my MainActivity
@Override
public void onBackPressed() {
if (drawer != null && drawer.isDrawerOpen()) {
drawer.closeDrawer();
} else {
AppUtilities.tapPromtToExit(this);
}
}
private void loadData() {
showLoader();
loadJson();
}
private void loadJson() {
StringBuffer sb=new StringBuffer();
BufferedReader br=null;
try {
br=new BufferedReader(new InputStreamReader(getAssets().open(AppConstants.CONTENT_FILE)));
String temp;
while ((temp=br.readLine()) != null) sb.append(temp);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
br.close();
} catch (Exception e) {
e.printStackTrace();
}
}
parseJson(sb.toString());
}
private void parseJson(String jsonData) {
try {
JSONObject jsonObject=new JSONObject(jsonData);
JSONArray jsonArray=jsonObject.getJSONArray(AppConstants.JSON_KEY_ITEMS);
for (int i=0; i < jsonArray.length(); i++) {
JSONObject object=jsonArray.getJSONObject(i);
String categoryId=object.getString(AppConstants.JSON_KEY_CATEGORY_ID);
String categoryName=object.getString(AppConstants.JSON_KEY_CATEGORY_NAME);
categoryList.add(new CategoryModel(categoryId, categoryName));
}
} catch (JSONException e) {
e.printStackTrace();
}
hideLoader();
adapter.notifyDataSetChanged();
}
private void initListener() {
// recycler list item click listener
adapter.setItemClickListener(new ListItemClickListener() {
@Override
public void onItemClick(int position, View view) {
CategoryModel model=categoryList.get(position);
ActivityUtilities.getInstance().invokeCommonQuizActivity(activity, QuizPromptActivity.class, model.getCategoryId(), true);
}
});
}
}
Answer the question
In order to leave comments, you need to log in
Give the code as normal. In android, in addition to RecyclerView and RecyclerViewAdapter, there is also a ListView, which is also used in conjunction with an adapter.
Further, maybe I don’t understand something (I still do lists on the ListView out of habit and for compatibility reasons, I didn’t touch the RecyclerView normally, since there were no tasks with large lists), but how is onItemClickListener () hung on the adapter? Or do you have your own implementation of the adapter, through the method of which you assign to the target RecyclerView an anonymous implementation of the ListItemClickListener class, inherited from RecyclerTouchListener ????
I was not too lazy, and googled ListItemClickListener in the blog of some deeply respected Indian: ListItemClickListener
Did you copy-paste from there? And where did you copy-paste then the "brilliant" decision to assign event processing not to the View, but to the adapter? This fundamentally contradicts the MVC dataset-adapter-view architecture. And it's good that the blog with the ListItemClickListener example just uses a stupid class naming scheme that is confusing. Here is an architectural error at the level of design patterns.
In summary, the provided code is not enough, on the face of a design error and a completely stupid naming of descendant classes. Also, I don't understand why to inherit from a regular descendant of the abstract RecyclerView.OnItemTouchListener in an anonymous class. What kind of game is this anyway?
There is no point in looking for errors. The provided code is not enough and some kind of game with a specific implementation of the adapter and RecyclerView.OnItemTouchListener. Here is a tutorial, I read it, you can do it right: https://www.androidhive.info/2016/01/android-worki...
According to the current code associated with RecyclerView, you can leave only layouts. And that's it. Rewrite the rest. In this code, I see little-meaning Frankenstein from copy-paste. I hope you are just learning. If this is a commercial project of some company, please give me its name in a personal. I will bypass her products, just if it is planned as a real code, I don’t want to deal with such a “[email protected]@k, [email protected]@k and in production” product, as well as work with such people.
UPD.1 Once again I went over the code with my eyes. What is this game?
private void loadData() {
showLoader();
loadJson();
}
hideLoader();
adapter.notifyDataSetChanged();
@Override
public void onBackPressed() {
if (drawer != null && drawer.isDrawerOpen()) {
drawer.closeDrawer();
} else {
AppUtilities.tapPromtToExit(this);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question