Android ListView setSelection() does not seem to work

前端 未结 17 1689
情歌与酒
情歌与酒 2020-11-28 06:45

I have a ListActivity that implements onListItemClick() and calls a doSomething() function of the class. The latter contains l.s

17条回答
  •  时光取名叫无心
    2020-11-28 06:54

    I found that sometimes setSelection will not work because I set attribute "android:height" of listView to "wrap_content".

    And the times my App won't work is that when listView become scrollable from non-scrollable.

    For example, if my app is "File Browser App". When my list is less than, let's say 6, then it's non-scrollable. Now I return to the parent directory, and it has 11 objects, and I want to set selection to some position, and it won't work here.

    to\from    |    Scrollable  | non-Scrollable
    

    Scrollable | O | O( of course )

    non-Scrollable | X | O( of course )

    I don't want to use post(Runnable), because there will has delay.

    ==================================

    Answer:

    You can try to set "android:height" to "match_parent"

    God, it spends three days.

提交回复
热议问题