[英]Child view focus change android
I have a ViewGroup
that can have many LinearLayout
s. 我有一个可以有很多
LinearLayout
的ViewGroup
。 And each LinearLayout
can have many nested child views. 每个
LinearLayout
都可以有许多嵌套的子视图。 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
. 我想要的是,如果
LinearLayout
任何视图(甚至是深层嵌套)获得焦点,它应该调用其主要父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. 我想做的最后一件事是,在
LinearLayout
每个深层嵌套子视图上设置OnFocusChangeListener
,该侦听器将调用其父级的自定义方法。 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 ? 是否有任何方法可以覆盖父
LinearLayout
,每次嵌套子视图的焦点更改时都会调用它?
您可以使用contentView.getViewTreeObserver().addOnGlobalFocusChangeListener()
或覆盖根ViewGroup的ViewGroup.requestChildFocus()
( requestChildFocus()
沿视图父链传递)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.