简体   繁体   中英

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM