开发者

What is the proper way to handle child selection when an ExpandableListView gets focus?

开发者 https://www.devze.com 2023-03-29 08:16 出处:网络
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开发者_如何学JAVA.

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开发者_如何学JAVA.

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消