For the problem to be solved, it is necessary to check the records loaded from the server with the SQLite base of the device itself and add / delete when absent / present (add to favorites). Already made a method to fill ExpandableListView , but I do not know how to add an ImageButton to the parent group. Below is the code of the method itself.

 public void setExpandableListView(ArrayList<Dish> val){ Map<String, String> map; ArrayList<Map<String, String>> groupDataList = new ArrayList<>(); ArrayList<Dish> values = val; for (int i = 0; i < values.size(); i++) { map = new HashMap<>(); map.put("dishName", values.get(i).getName()); groupDataList.add(map); } String groupFrom[] = new String[] { "dishName" }; int groupTo[] = new int[] { android.R.id.text1 }; ArrayList<ArrayList<Map<String, String>>> сhildDataList = new ArrayList<>(); for (int i = 0; i < values.size(); i++) { ArrayList<Map<String, String>> сhildDataItemList = new ArrayList<>(); map = new HashMap<>(); map.put("dishRecipe", values.get(i).getRecipe()); сhildDataItemList.add(map); сhildDataList.add(сhildDataItemList); } String childFrom[] = new String[] { "dishRecipe" }; int childTo[] = new int[] { android.R.id.text1 }; final SimpleExpandableListAdapter adapter = new SimpleExpandableListAdapter( this, groupDataList, android.R.layout.simple_expandable_list_item_1, groupFrom, groupTo, сhildDataList, android.R.layout.simple_list_item_1, childFrom, childTo); final ExpandableListView list = (ExpandableListView) findViewById(R.id.list_recipes); list.setAdapter(adapter); list.deferNotifyDataSetChanged(); list.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View itemClicked, int position, long id) { } }); list.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (firstVisibleItem + visibleItemCount == currentNumOfDishes){ String[] query = new String[2]; query[1] = "get_dishes"; query[0] = "SELECT * FROM Dishes WHERE _id > " + currentNumOfDishes + " AND _id <= " + neededNumOfDishes; new AsyncRequest(Recipes_List.this).execute(query); scroll = currentNumOfDishes; scrollcount = visibleItemCount; currentNumOfDishes = neededNumOfDishes; neededNumOfDishes += 20; } } }); if (scroll > 1){ list.setSelectedGroup(scroll-scrollcount); } } 

    1 answer 1

    As a layout for groups, you now use the resource provided by Android: android.R.id.text1. You need to create your own layout resource for groups, with the necessary markup (adding an ImageButton, etc.), well, in the code, you should refer to it accordingly. Well, most likely the same should be done for the child elements.

    • And to place the markup ImageButton and TextView, as I understand it? - Vsevolod
    • 2
      Yes, you create the markup that you need. If you need ImageButton and TextView then you place them in it. - ZigZag
    • thanks a lot, as I’ll make a note) - Vsevolod
    • it is even embarrassing to worry, but the problem was not solved, because no response to the replacement of the resource for the groups can be obtained (either positive or negative). I did the following change: ... int groupTo [] = new int [] {R.drawable.fav_adapter }; ... fav_adapter.xml looks like this: <? xml version = "1.0" encoding = "utf-8"?> <selector xmlns: android = " schemas.android.com/apk/res/android "> <ImageButton android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: id = "@ + id / imageButton" android: layout_below = "@ + id / group" - Vsevolod
    • android: layout_alignParentLeft = "true" android: layout_alignParentStart = "true" android: background = "@ android: drawable / btn_star_big_off" /> <TextView android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "New Text "android: id =" @ + id / textView "android: layout_alignParentTop =" true "android: layout_alignParentLeft =" true "android: layout_alignParentStart =" true "/> </ selector> (I apologize, in the comments there is no normal formatting) - Vsevolod