I have a EditText, and a popupWindown(which has a ListView in it), now i touch the EditText, the popupWindow shows.
i need the situation: i can input something in SoftInput, and i also can click a child item in ListView which is the children of PopupWindow.
Now, i can only input, or can only click listview , i can't do the both thing in Android 4.1, 4.2. But i can do both in Android 4.4, 5.0。
I tried in many ways, like popupWindo.setFocus(true), which only make the EditText lose the focus.
So, Can android allow two views both have focus ?
No, two (or more) views cannot have focus at the same time, not possible.
Here is how to change focus from one textView to another textView. Which you could change in your case.
Actually, technically speaking two views can have focus at the same time - not just as you would imagine (and as you would need for your usecase):
The parents of a focused view can also have their focus set to true. Cf. an excerpt from an example view hierarchy, has-focus=true
pops out more than once:
View Hierarchy:
+>DecorView{id=-1, visibility=VISIBLE, width=1920, height=1080, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false,
|
+->LinearLayout{id=-1, visibility=VISIBLE, width=1776, height=1080, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=fal
|
+-->ViewStub{id=16909243, res-name=action_mode_bar_stub, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-f
|
+-->FrameLayout{id=-1, visibility=VISIBLE, width=1776, height=1008, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=fal
|
+--->FitWindowsLinearLayout{id=2131296268, res-name=action_bar_root, visibility=VISIBLE, width=1776, height=1008, has-focus=true, has-focusable
|
+---->ViewStubCompat{id=2131296279, res-name=action_mode_bar_stub, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, ha
|
+---->ContentFrameLayout{id=16908290, res-name=content, visibility=VISIBLE, width=1776, height=1008, has-focus=true, has-focusable=true, has-wi
|
+----->LinearLayout{id=-1, visibility=VISIBLE, width=1776, height=1008, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable
|
+------>RecyclerView{id=2131296483, res-name=lstRecordings, visibility=VISIBLE, width=1776, height=873, has-focus=true, has-focusable=true, has
来源:https://stackoverflow.com/questions/27289381/can-two-views-both-have-focus-in-android