i have many text views in activity. example if click on colour text view. dialog appear list of colours populated mcolourarray. should able choose colours , return results in mcolourarrayselected. same goes malphabetarray , malphabetarrayselected.
the problem below when try assign assign mcolourarrayselected in case statment empty because resultlist inside multidialog not returned in onclick event.
it wont let me change onclick return list how implement callback?
@override public void onclick(view view) { switch (view.getid()) { case r.id.textviewcolour: mcolourarrayselected = multidialog(mcolourarray); break; case r.id.textviewalphabet: malphabetarrayselected = multidialog(malphabetarray); break; break; } } public list<string> multidialog(final list<string> list ) { resultlist.clear(); final string[] array = new string [list.size()] ; (int i=0; i<list.size(); i++) { array[i]=list.get(i); } final arraylist mselecteditems = new arraylist(); // track selected items alertdialog.builder builder = new alertdialog.builder(searchactivity.this); // set dialog title builder.settitle("multi select") // specify list array, items selected default (null none), // , listener through receive callbacks when items selected .setmultichoiceitems(array, null, new dialoginterface.onmultichoiceclicklistener() { @override public void onclick(dialoginterface dialog, int which, boolean ischecked) { if (ischecked) { // if user checked item, add selected items mselecteditems.add(which); } else if (mselecteditems.contains(which)) { // else, if item in array, remove mselecteditems.remove(integer.valueof(which)); } } }) // set action buttons .setpositivebutton(r.string.ok, new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int id) { // user clicked ok, save mselecteditems results somewhere // or return them component opened dialog (int i=0; i<mselecteditems.size(); i++) { int pos = (int) mselecteditems.get(i); resultlist.add(list.get(pos)); } } }) .setnegativebutton(r.string.cancel, new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int id) { } }); alertdialog dialog = builder.create(); dialog.show(); return resultlist; }
Comments
Post a Comment