On some Android versions ListView inside PopupWindow doesn't receive touch events when popup is not focusable? -
ok, have following requirements:
- an edittext in if user types @ popup suggestions appears
- the user can continue typing filter suggestions
- the user can tap on suggestion complete entry , dismiss popup
- the user can tap outside popup dismiss it
here code:
popupwindow popupwindow = new popupwindow(mcontext); // create listview show suggestions listview listview = new listview(mcontext); listview.setbackgroundcolor(color.white); mentionsadapter adapter = new mentionsadapter(mcontext, suggestions); listview.setadapter(adapter); listview.setonitemclicklistener(new android.widget.adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { string username = msuggestions.get(position); string mentioncompletion = username.substring(mcurrentquery.length()).concat(" "); meditor.gettext().insert(meditor.getselectionend(), mentioncompletion); hidesuggestions(); } }); msuggestionslistview = listview; popupwindow.setcontentview(listview); popupwindow.setfocusable(false); popupwindow.settouchable(true); popupwindow.setoutsidetouchable(true); popupwindow.setondismisslistener(new popupwindow.ondismisslistener() { @override public void ondismiss() { clearpopupdata(); } }); rect popuprect = calculatepopupposition(); popupwindow.setwidth(popuprect.width()); popupwindow.setheight(popuprect.height()); popupwindow.showatlocation(meditor, gravity.start | gravity.top, popuprect.left, popuprect.top); mpopupwindow = popupwindow;
it work! problem works on android versions/devices. example works on android 6.0 on emulator doesn't work on colleague's lg g4 6.0. doesn't work on android 4.3.1 works on 4.4.2. if popupwindow
not focusable listview
's onitemclicklistener
not called. if popupwindow
focusable listview
's onitemclicklistener
called edittext
doesn't receive keyboard events. tried countless combinations of changing focus/touch modes on popupwindow
, listview
, couldn't working in cases.
any suggestions on wft going on , how fix it?
i found way achieve want. more hack real answer why inconsistent behavior happening not accept answer. still, may valuable people looking achieve same requirements.
what did surrender , make popupwindow
focusable in order enable it's embedded listview
receive touch events:
popupwindow.setfocusable(true);
as makes listview
receiver of keyboard events made onkeylistener
forwards events edittext:
listview.setonkeylistener(new view.onkeylistener() { @override public boolean onkey(view v, int keycode, keyevent event) { meditor.dispatchkeyevent(event); return false; } });
for clearance here complete modified code question:
popupwindow popupwindow = new popupwindow(mcontext); // create listview show suggestions listview listview = new listview(mcontext); listview.setbackgroundcolor(color.white); listview.setonkeylistener(new view.onkeylistener() { @override public boolean onkey(view v, int keycode, keyevent event) { meditor.dispatchkeyevent(event); return false; } }); mentionsadapter adapter = new mentionsadapter(mcontext, suggestions); listview.setadapter(adapter); listview.setonitemclicklistener(new android.widget.adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { string username = msuggestions.get(position); string mentioncompletion = username.substring(mcurrentquery.length()).concat(" "); meditor.gettext().insert(meditor.getselectionend(), mentioncompletion); hidesuggestions(); } }); msuggestionslistview = listview; popupwindow.setcontentview(listview); popupwindow.setfocusable(true); popupwindow.settouchable(true); popupwindow.setoutsidetouchable(true); popupwindow.setondismisslistener(new popupwindow.ondismisslistener() { @override public void ondismiss() { clearpopupdata(); } }); rect popuprect = calculatepopupposition(); popupwindow.setwidth(popuprect.width()); popupwindow.setheight(popuprect.height()); popupwindow.showatlocation(meditor, gravity.start | gravity.top, popuprect.left, popuprect.top);
this seems work on android versions/devices. if visual focusing of items in listview
not desired can set background of listview
's items color or drawable doesn't change when focused.
Comments
Post a Comment