getting View for ListView item / reverse order on 2.2; works on 4.0.3

前端 未结 1 918
盖世英雄少女心
盖世英雄少女心 2021-01-19 05:26

I have a ListView which shows items from ArrayAdapter. I want to animate the view when it is cliked. The problem is that on different versions of android I am getting differ

相关标签:
1条回答
  • 2021-01-19 05:52

    OK. so this is what is happening :

    On a clean ListView When I register onItemClickListener and perform clicks adapter getView method for views is not called. This is what I would expect.

    If I set a mList.setChoiceMode(ListView.CHOICE_MODE_SINGLE) this makes getView methods run right after click is registered. This is also what is expected.

    However the difference between 2.2 and 4+ versions is that : on 2.2 : when this refresh happens getView operates on a reversed list of views (see my question) on 4+ (possibly API 11+) : getView operates on normal order of list

    What is the most interesting part is that when I delay call to getViewForListPosition by 10ms everything works fine and adapter has proper list of views (normal order again). So it seems that the order of views is reversed only during adapter refresh with CHOICE_MODE_SINGLE

    To solve this problem I dont change listview mode to CHOICE_MODE_SINGLE so that adapter doesn't fire during click. I set bg/graphics for clicked item on my own inside onItemClicked

    hope that it saves someone some time :)

    0 讨论(0)
提交回复
热议问题