ListView custom filter gives wrong item selected when filtered [Android]

前端 未结 1 928
醉话见心
醉话见心 2020-12-11 17:52

I am new to Android programming and I have a ListView when filtered always return me the first item in the list, so how do I fix this?

For instance, my list contains

相关标签:
1条回答
  • 2020-12-11 18:21

    Because you filter your adapter to have B.C in position 0 and B.D in position 1. But in your implementation of your onClickListener, you use the listview's position to get directly from the source ArrayList.

    String a = patientArrayList.get(position);
    

    Instead to get it from the filtered adapter:

    String a = parent.getAdapter().getItem(position);
    

    or

    String a = parent.getItemAtPosition(position);
    
    0 讨论(0)
提交回复
热议问题