1

I have a ListView where I store a list of order.

When clicking an item, it should expand to let the user see the detail.

The problem is that the item is actually expanding, but so is another item randomly in the list.

If I scroll the list while one item is open, the first item collapse and another take his place. The second expanded item is NEVER in sight, I have to scroll to see it.

I don't understand anything to this bug, can you help me?

Here is the listener that interract with the listview

public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
     View v = CommandesSalarieActivity.this.list.getChildAt(position);
     LinearLayout ll = view.findViewById(R.id.commande_salarie_list_item_layout_main_layout);
     ImageView iv = view.findViewById(R.id.commande_salarie_list_item_layout_dropdown);
     if (ll.getVisibility() == View.VISIBLE) {
            ll.setVisibility(View.GONE);
            iv.setImageResource(R.drawable.ic_dropdown_ressource);
     } else {
             ll.setVisibility(View.VISIBLE);
             iv.setImageResource(R.drawable.ic_dropup_ressource);
     }
}
Ricardo A.
  • 586
  • 2
  • 7
  • 32
Arrowbase
  • 13
  • 2
  • I think it's because you are just updating the view, not the data set. So when the item is destroyed and recreated, it's getting confused. First of all, I recommend using RecylerView, not ListView because ListView is very old and not updated anymore. Check this out https://stackoverflow.com/questions/31367599/how-to-update-recyclerview-adapter-data – MSpeed May 28 '19 at 14:17
  • Okay I didn't knew that ListView was deprecated. Thank you for your answer ! I'll have a look at recycler view. – Arrowbase May 28 '19 at 14:44
  • No matter ListView/RecyclerView, there is an **adapter** which populate **item views** according to **dataSet/dataList**. Change in item view without updating dataSet is a wrong approach. My detailed explaination is here: http://programandroidlistview.blogspot.com/2016/12/inandroid-listview-gridview-spinner-are.html Pls update the post with adapter code. – i_A_mok May 29 '19 at 15:28

0 Answers0