Nice post btmura, Thank you! I have a similar problem with the Gallery widget loosing focus. I'm dynamically loading images from the internet with an image adapter. Whenever I fetch a new set of pages and tell the image adapter to update itself, the focus in the gallery jumps away. When I move focus back to the gallery, the page that's selected still cannot gain focus until I press left or right once to select another page and then back again to select the page that lost focus.
I'm not sure if updating the image adapter inexplicitly calls the requestLayout function that btmura mentioned above. Has anybody else come up with a good way to ensure that a Gallery maintains it's focus correctly? Thanks! On Jan 8, 12:00 am, "btm...@gmail.com" <btm...@gmail.com> wrote: > Hello all, > > I have a simple layout with a Gallery and a ListView. What I want to > do is move through the gallery using the trackball and update the > ListView as I select items in the Gallery. However, there is a problem > where the gallery loses focus as soon as it selects an item. I don't > think this is the right behavior, so I started digging into the > details and here is what I found. > > I start out with the Gallery focused. When I move the trackball to the > right, the Gallery properly focuses the next selected view and calls > the onItemSelected callback. My OnItemSelectedListener's > onItemSelected calls the ListView adapter's "notifyDataChanged" method > to update the ListView. The "notifyDataChanged" method calls onChanged > of the data observer. The data observer is the AdapterView's > AdapterDataSetObserver, and that method calls requestLayout. The > requestLayout triggers a traversal of the entire view tree and then > the Gallery's layout method unfocuses the selected item. It then > throws the focus off completely. > > What I had to do to work around this was create a sub-class of > ListView and override the requestLayout method to do nothing. Then I > had to make layoutChildren public. Finally, I just called > layoutChildren after each notifyDataChanged call I made to the > adapter. > > Is there an alternate way to update my ListView in response to > selecting an item in the gallery? Or do we have a problem here? > > My last note is I think Gallery has a bug here. It seems if you call > layout a second time, it will lose focus? > > Please let me know if you need a concrete code example. > > Thank you, > -Brian --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---