当 ExpandableListView 获得焦点时,处理子项选择的正确方法是什么?
我有一个 ExpandableListView
以及一些其他可以将焦点放在其右侧的控件。像这样的东西。注意:选择 Child2。
Group1
Child1 +-----------------------+
*Child2* | |
Child3 | Other focusable View. |
Child4 | |
Child5 +-----------------------+
使用方向键,如果我按向右,焦点就会转到另一个视图。此时,如果我按方向键上的向左键,焦点将返回到我的 ExpandableListView
,但 Child3 会被选中,而不是 Child2(因为它位于中心)。
一般来说,当焦点离开然后返回到我的 ExpandableListView
时,如何确保先前选定的子项仍然是选定的子项?关于解决方法有什么想法吗?我尝试缓存当前选择,然后调用 setChildSelected()
,但由于某种原因,选择没有发生。
I have an ExpandableListView
and then some other control that can have focus to the right of it. Something like this. Note: Child2 is selected.
Group1
Child1 +-----------------------+
*Child2* | |
Child3 | Other focusable View. |
Child4 | |
Child5 +-----------------------+
Using the d-pad, if I press right, focus goes to the other view. At that point if I press left on the d-pad, focus returns to my ExpandableListView
, but Child3 gets selected instead of Child2 (because it's in the center).
In general, how can I ensure that the previously selected child remains the selected child when focus leaves and then returns to my ExpandableListView
? Any ideas on a work around? I tried caching the current selection then calling setChildSelected()
, but for some reason the selection doesn't happen.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我通过在失去焦点时缓存当前组和子项来解决这个问题,然后在列表视图重新获得焦点时显式地重新设置组/子项。我还必须禁用列表视图并在不同的地方重新启用它。这是一个 hack,但它确实有效。
Well, I solved it by caching the current group and child when focus is lost and then explicitly re-setting the group / child when the listview re-gains focus. I had to also disable the listview and re-enable it in various places. It's a hack, but it works.