android - How to dispatch touchevent from popupwindow to its child listview -


i'm using popupwindow show suggestions when user type on edittext. inside popup window, have listview shows suggestions. couldn’t use listpopupwindow because covering keyboard user can't able continue typing while popup showing.

in order user continue typing, have setfocusable(false); on popupwindow. issue 1 cannot click on suggestion since window not focusable. , if make focusable, user won't able continue typing since focus removed edit text popup window. therefore have set touchlistener popupwindow , perform click programmatically.

how can intercept popupwindow touchevent , perform click on listview item? tried using code snippet below never worked

  public void initpopupwindow(int type) {      mpopupwindow = new popupwindow(popupview, viewgroup.layoutparams.wrap_content, viewgroup.layoutparams.wrap_content);       mpopupwindow.setinputmethodmode(popupwindow.input_method_needed);    mpopupwindow.setfocusable(false);   mpopupwindow.setoutsidetouchable(true);   mpopupwindow.settouchinterceptor(new popuptouchinterceptor());    view view1 = layoutinflater.from(context).inflate(r.layout.search_listview,null);   mdropdownlist = (customlistview)view1.findviewbyid(r.id.searchlistview);   serchadapter = new searchadapter(context,realm);   mdropdownlist.setadapter(serchadapter);   mdropdownlist.setonitemclicklistener(new adapterview.onitemclicklistener() {     @override     public void onitemclick(adapterview<?> parent, view view, int position, long id) {       searchableedittext.settext(serchadapter.getitem(position).tostring());       mpopupwindow.dismiss();     }   });   mpopupwindow.setcontentview(view1);     }     private class popuptouchinterceptor implements view.ontouchlistener {     public boolean ontouch(view v, motionevent event) {       final int action = event.getaction();       boolean consumed = false;       boolean handledevent = true;       boolean clearpresseditem = false;       final int actionmasked = event.getactionmasked();        if (action == motionevent.action_down) {         consumed = true;         mactivepointerid = event.getpointerid(0);        } else if (action == motionevent.action_up) {         consumed = true;        }else if(action == motionevent.action_outside){         consumed = true;        }else if(action == motionevent.action_move){          consumed = true;           final int activeindex = event.findpointerindex(mactivepointerid);          final int x = (int) event.getx(activeindex);         final int y = (int) event.gety(activeindex);         final int position = mdropdownlist.pointtoposition(x, y);          final view child = mdropdownlist.getchildat(position - mdropdownlist.getfirstvisibleposition());         handledevent = true;         child.performclick();        }       return consumed;     }   } 

i found way achieve want.

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:

public void initpopupwindow(int type) {      mpopupwindow = new popupwindow(popupview, viewgroup.layoutparams.wrap_content, viewgroup.layoutparams.wrap_content);       mpopupwindow.setinputmethodmode(popupwindow.input_method_needed);    mpopupwindow.setfocusable(true);   mpopupwindow.setoutsidetouchable(true);    view view1 = layoutinflater.from(context).inflate(r.layout.search_listview,null);   listview = (listview)view1.findviewbyid(r.id.searchlistview);   serchadapter = new searchadapter(context,realm);   listview.setadapter(serchadapter);   listview.setonitemclicklistener(new adapterview.onitemclicklistener() {     @override     public void onitemclick(adapterview<?> parent, view view, int position, long id) {       searchableedittext.settext(serchadapter.getitem(position).tostring());       mpopupwindow.dismiss();     }   });    listview.setonkeylistener(new view.onkeylistener() {             @override             public boolean onkey(view v, int keycode, keyevent event) {                 meditor.dispatchkeyevent(event);                 return false;             }         });   mpopupwindow.setcontentview(view1);   } 

Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -