The fact is that my Expandable Group is divided into two, that is, for groupText separate click, and for the indicator, another click, that is, the indicator is groupItem .

enter image description here

And I need to make it so that when I click on groupText(rubricItem) switch to another fragment and its Background stand out, and remain selected when going backwards. So here I have it stands out in this way:

 groupViewHolder.mSelectedGroupItem = (View) convertView.findViewById(R.id.selectedGroupView); ...................... groupViewHolder.groupText.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!finalConvertView.isActivated()) { finalConvertView.setActivated(true); groupViewHolder.mSelectedGroupItem.setVisibility(View.VISIBLE); } } }); ..................... 

it stands out, but when you click on another groupText(rubricItem) first one remains selected. And with scrolling, almost half of all `groupText is allocated.

Question: How to select? And when scrolling maintained its state?

    1 answer 1

    This is an eternal question. The solution is:

    1. Enter a variable in the adapter (list of variables for multiple selection) in which you store the position of the selected element.
    2. In the methods of drawing elements, check whether the current position is in the selected number and, depending on this, display the selected / unselected view.
    3. When you click on an item, add its position to the above list.
    4. Provide a way to remove an item from the list.
    5. If you need to save when turning the screen - save the list from the adapter in the activation / fragment
    • I did not quite understand the 4-point, how to provide.? - DevOma pm
    • @TITAN, well, for example, if an item is clicked, then clicking will remove the position from the list - otherwise add and open another screen. At this point, everything depends on you - YuriySPb
    • Thanks, I understood the campaign, I will try ... - DevOma September
    • Another question, do you mean to keep them in hashMap? - DevOma pm
    • one
      Thanks for the tip, it helped a lot !!! - DevOma