Android: Why onTouchListener() opens multiple Alert Dialog? -
i want open alert dialog containing autocomplete textview when click spinner. here's code
resnonres = (spinner)activity.findviewbyid(componentnameidmap.get("spinner")); resnonres.setontouchlistener(touch); ontouchlistener touch = new ontouchlistener(){ @override public boolean ontouch(view v, motionevent event) { final autocompletetextview av = new autocompletetextview(activity); av.setadapter((arrayadapter)resnonres.getadapter()); alertdialog.builder buildersingle = new alertdialog.builder(activity); buildersingle.settitle("exception"); buildersingle.setview(av); buildersingle.setpositivebutton("ok", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int whichbutton) { string avv = av.gettext().tostring(); arrayadapter myadap = (arrayadapter) resnonres.getadapter(); //cast arrayadapter int spinnerposition = myadap.getposition(avv); //set default according value resnonres.setselection(spinnerposition); } }); buildersingle.setnegativebutton("cancel", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int whichbutton) { // canceled. } }); buildersingle.show(); return false; } };
but opens more 1 alert dialogs.
i can not use onclick listeners spinner not support item click events neither can use onitemselectedspinner because of contraints in project using general spinners.
please suggest...
because you're doing touch events- ups, down, moves, etc. should on up.
Comments
Post a Comment