失去当前选择的列表项的更新使用列表视图项目后notifyDataSetChanged [英] Losing current selection of list item after updating the listview items using notifyDataSetChanged
问题描述
我需要刷新的ListView项目每一秒,并使用notifyDataSetChanged正常工作()。刷新之后,在列表中的已选择的项目正在失去它的选择。也就是说,就失去了选择的项目的背景。我怎样才能保持已选定项目的选定状态,在每次刷新?
I need to refresh the ListView items every second, and it works fine using notifyDataSetChanged(). After the refresh, the already selected item in the list is losing its selection. ie, it loses its selected item background. How can I maintain the selected state of already selected item, after each refresh?
感谢ü提前为支撑。
推荐答案
据我理解你的问题你的查询是你失去了选择的项目重点在ListView的刷新的ListView之后。所以,你可以使用 ListView的setSelection()方法
设置所选的项目,ListView控件。所以,当你刷新后ListView控件,您可以设置要选择或项目使用选择的previous setSelection()。
As I understood your question your query is that you are losing the selected item focus of the ListView after refreshing the ListView. So, for that you can use ListView's setSelection() method
to set the selected item in the ListView. So, when you refresh the ListView after that you can set the item that you want to be selected or the previous selected using setSelection().
listView.setSelection(position)
下面位置
是之前的最后选择的索引位置 notifyDataSetChanged()
Here position
is the position that was the last selected index before notifyDataSetChanged()
这篇关于失去当前选择的列表项的更新使用列表视图项目后notifyDataSetChanged的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!