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); } }