开发者

Android ListAdapter next button

开发者 https://www.devze.com 2023-04-06 04:59 出处:网络
I use a listview to display items from the database and I\'m using the ArrayAdapter to hold the items in the list. I am displaying 25 items at a time with a next/prev button at the bottom of the list.

I use a listview to display items from the database and I'm using the ArrayAdapter to hold the items in the list. I am displaying 25 items at a time with a next/prev button at the bottom of the list. When the user clicks the next button I clear the ArrayList, add the new items, and preform the ListAdapter开发者_JS百科.notifyDataSetChanged(). This all works fine for displaying the next 25 items however, the listview stays at the bottom instead of returning to the top.

How do you return to the first item in the list view?


You have a couple of choices to choose from. Here are the methods. Try from top to bottom order.

  • setSelection(int position)
  • smoothScrollToPosition(int position)
  • setSelectionAfterHeaderView()
  • setSelectionFromTop(int position, int y)

setSelection methods will position your listview nicely. If you use setSelection(0), it will show you from the start of listview. Just a caution, use this method after you had populated your listview.


 myListAdapter.smoothScrollToPosition(0);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号