简体   繁体   English

ListView始终位于最前面

[英]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. 使用由ArrayList支持的ArrayAdapter。 To change the data, just update the data in the list and call 要更改数据,只需更新列表中的数据并调用

MyAdapter.notifyDataSetChanged(). MyAdapter.notifyDataSetChanged()。

Although you can call notifyDataSetChanged() on SimpleAdapter too. 尽管您也可以在SimpleAdapter上调用notifyDataSetChanged()。

You need to add listview.setSelection(your_collection.size()); 您需要添加listview.setSelection(your_collection.size()); . This will make the last item in the ListView as selected when you refresh the ListView. 当刷新ListView时,这将使ListView中的最后一项处于选中状态。 Also call this after refereshing the ListView. 在刷新ListView之后也调用此方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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