如何使用 OnItemClick 刷新 ListView 中单行的内容
我有一个带有复选框的列表视图。 我想要实现的是一个 onItemClick (在我的活动中),如果我单击该行,它会检查/选择我的复选框,如下所示:
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
MyItem row = ListofRows.get(position);
row.setSelected(true);
myAdapter.notifyDataSetChanged();
}
当我单击该行时,由于方法 notifyDataSetChanged( )
问题是:此方法会刷新整个 ListView,因此,即使用户位于列表的底部,ScroolBar 也会转到开头(用户被驱动到列表的标题)这 列表。
我需要的是:仅刷新这一单击的行,这样用户就不会被带到列表的开头。
这个问题有什么解决办法吗?
I have a ListView with a CheckBox.
What I am trying to implement is an onItemClick (in my activity) that check/select my CheckBox if I click on the row, as you can see below:
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
MyItem row = ListofRows.get(position);
row.setSelected(true);
myAdapter.notifyDataSetChanged();
}
When I click in the row, the ListView is refreshed because of the method notifyDataSetChanged()
THE PROBLEM IS: this method refreshes the whole ListView and as a result, the ScroolBar goes to the beginning (the user is driven to the header of the list) even if the user is at the bottom of the list.
WHAT I NEED IS: Refresh just this single clicked row so the user won't be driven to the beginning of the list.
Are there any solutions to this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用选定的索引
查看 v = getListView.getChildAt(index);
现在用新值更新视图。
use the selected index
View v = getListView.getChildAt(index);
Now update the view with the new values.