For my task for all Group elements in ExpandableListView use xml with TextView and ImageView . Further, for some reason, I need some elements of the Group to change the ImageResource in the ImageView . I wrote this code:

  for (int i : fav_numbers){ ImageView imgView = (ImageView) adapter.getGroupView(i, false, null, null).findViewById(R.id.pic); imgView.setImageResource(android.R.drawable.star_big_on); } adapter.notifyDataSetChanged(); //adapter здесь типа SimpleExpandableListAdapter list.setAdapter(adapter); 

The code is executed, but no changes occur (the image on the elements remains the same). Are there any errors in calling the getGroupView method (I suspect there may be a null, null problem) or need to do it in some other way?

    1 answer 1

    Changing the layout of the adapter must be inside the adapter, not outside.

    1. In the getGroupView method, getGroupView need to put different pictures on some condition.
    2. The condition must be in the list ( ArrayList ) data.
    3. At the right time, change the condition in this list and notify the adapter about the changes. notifyDataSetChanged()
    4. The adapter will call the getGroupView method and according to the changed condition the markup will be changed.
    • Is it possible to somehow do without rewriting the method? I used notify further, but still no result (Just this list.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { ImageView imgView = (ImageView) view.findViewById(R.id.pic); imgView.setImageResource(android.R.drawable.star_big_on); return true; } }); work quietly - Vsevolod
    • That is, even when called via the ExpandableListView event and not the adapter is triggered - Vsevolod
    • @Vsevolod, do you have a GetGroupView assigned to GetGroupView ? If so, the old one is assigned after the cycle. But in general - the proposed method is the right one. And changing something through a call to GetGroupView is not correct. - Yuriy SPb