即使在失去焦点后如何突出显示选定的列表项?
我正在构建的活动之一包含一个 ListView
和一个 GridView
。 gridview 的内容将根据 ListView 中选择的项目进行更新。现在,我使用选择器通过更改背景来突出显示 ListView 中的所选项目。但是一旦 ListView 失去焦点,所选项目就不再突出显示。有没有办法即使在列表视图失去焦点后也可以突出显示列表项?
One of the activities I'm building contains a ListView
, and a GridView
. The contents of the gridview will be updated based on the item selected in the ListView. Now, I'm using a selector to highlight the selected item in ListView by changing its background. But once the ListView loses focus, the selected item is not highlighted anymore. Is there a way to have the list item highlighted even after the focus is lost by the list view?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
设置您的选择器以识别激活状态
,不仅选择,而且激活它
onListItemClick
Set your selector to recognize the activated state
And not only select, but activate it
onListItemClick
我认为您想维护某些列表的单击项目的状态。为此,您可以使用布尔 ArrayList 来维护列表每一行的状态。您可以在 Adapter 的 getView() 中使用这个 ArrayList。根据状态设置背景。例如,在 getView() 中设置 View 的背景图像或颜色。 这里是我正在谈论的一个想法。您也可以将其用于您的目的。
I think you want to maintain the state of the clicked Item of some List. For this you can use a boolean ArrayList to maintain the state for every row of list. And you can use this ArrayList in the getView() of your Adapter. Set the background depending on the state. e.g. Set the background image or color of the View in getView() . Here is an idea that I am talking about. You can use it for your purpose as well.