简体   繁体   中英

ListView always on top

I use below code to update listview.

setListAdapter(MyAdapter);
MyAdapter.notifyDataSetChanged();
getListView().setEmptyView(empty);

But each time update, the list always show top one. I want to let it only update data, but not focus on top. How to do it?

Use a ArrayAdapter backed by an ArrayList. To change the data, just update the data in the list and call

MyAdapter.notifyDataSetChanged().

Although you can call notifyDataSetChanged() on SimpleAdapter too.

You need to add listview.setSelection(your_collection.size()); . This will make the last item in the ListView as selected when you refresh the ListView. Also call this after refereshing the ListView.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM