Android ArrayAdapter 告诉所有其他视图自行刷新
我需要 arrayadapter 中的所有其他视图来检查它们的属性并在某些时候返回默认属性
用例:listview items (a)(b)(c)(d) ,当您触摸 (a) 时,背景会转动黑色的。这是在 ontouchListener 中完成的。但是当你触摸视图(b)时,它的背景会变成黑色,但是(a)需要返回到默认值(不是黑色)
我涉足了在视图末尾调用数组适配器。OnClickListener 但这的问题是它还会重置视图的滚动位置,因此如果此列表更长(确实如此)并且用户触摸了项目 (r) ,那么它将重置列表并将用户放回顶部的项目 (a)
我是正在查看 notifydatasetchanged
但我不确定如何使用它以及它应该在哪里工作
洞察力赞赏
I need all of the other views in my arrayadapter to check their attributes and return to a default attribute at certain times
use case: listview items (a)(b)(c)(d) , when you touch (a) it's background turns black. This is done in the ontouchListener. But when you touch view (b) it's background turns black BUT (a)'s needs to turn back to the default which is not black
I dabbled around with recalling the arrayadapter at the end of the view.OnClickListener but the problem with this is that it also resets the scroll position of the view, so if this list was much longer - which it is - and user touched item (r) , then it would reset the list and put the user back at item (a) at the top
I was looking at notifydatasetchanged
but I am not sure how to use that and where it should work
insight appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
notifyDataSetChanged
将完成这项工作。您可以随时在代码中调用它,这将触发适配器再次调用可见列表项的 getView ,从而更新其内容。因此基本上您唯一要做的就是在调用该方法之前更新列表项状态或信息。notifyDataSetChanged
will do the job. You can call that at any time in your code and this will trigger the adapter to callgetView
for the visible list items again and so update their content. So basically the only thing you have to do is to update the list item states or information before calling that method.