Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Child view focus change android

I have a ViewGroup that can have many LinearLayouts. And each LinearLayout can have many nested child views. What I want is that, if any view(even deep nested) inside a LinearLayout gets focus, it should call a custom method of its main parent LinearLayout.

The last thing I want to do is, set OnFocusChangeListener on every single deep nested child views of LinearLayout and that listener will call its parent's custom method. But that is really bad way to go for.

Is there any method I can override of parent LinearLayout that gets called every time its any nested child view's focus changes ?

like image 786
xmen Avatar asked Nov 25 '13 05:11

xmen


1 Answers

You could use contentView.getViewTreeObserver().addOnGlobalFocusChangeListener() or override ViewGroup.requestChildFocus() of the root ViewGroup (requestChildFocus() is passed along the view parent chain).

like image 126
Christian d'Heureuse Avatar answered Nov 20 '22 05:11

Christian d'Heureuse