Android 中预选 listView 中的项目
我需要的只是一个继续搜索的想法或路径,我有一个添加到列表视图适配器的项目列表。我试图在活动加载时使列表中的某些项目具有特定的背景颜色(作为示例)。就像“预选”这些行一样。方法 public ListView getListView()
对我没有多大帮助。 不管怎样谢谢你。
All i need is an idea or path to continue searching, i have a list of items that i add to a listview adapter. And i am trying to make some items in the list to have a specific background color (as an example) when the activity loads. Something like having those rows "preselected". The method public ListView getListView()
does not help me much.
Thank you either way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
需要通过 setChoiceMode(),然后你可以调用 setItemChecked() 对于每个项目你想要检查。然后您可能必须制作一个自定义适配器来覆盖 getView(),将父级转换为 ListView 并询问您在给定位置获取的视图(列表项)是否实际上通过调用类似的方法进行检查<一href="http://developer.android.com/reference/android/widget/AbsListView.html#getCheckedItemPositions%28%29" rel="noreferrer">getCheckedItems() 在父级上。然后您可以对该视图执行任何您想要的操作,例如设置其背景颜色等。
Need to set Multiple Choice Mode via setChoiceMode(), and then you can call setItemChecked() for each of the items you want checked. Then you probably have to make a custom adapter that overrides getView(), cast the parent to ListView and ask if the View (a list item) you are getting at the position given is in fact checked by calling something like getCheckedItems() on the parent. Then you can do what ever you want with that view, like set its background color etc.