alertdialog - How to show alert confirmation dialog from listview button in android -
i trying show confirmation dialog after clicking on button in listview.
i have setonclicklistener in customadapter in getview method.
but on click listener getting following error:
02-25 21:36:32.065 20631-20631/com.themsg.chat w/toast: com.themsg.chat, go ahead. 02-25 21:36:32.095 20631-20631/com.themsg.chat w/system.err: android.view.windowmanager$badtokenexception: unable add window -- token null not application 02-25 21:36:32.095 20631-20631/com.themsg.chat w/system.err: @ android.view.viewrootimpl.setview(viewrootimpl.java:569) 02-25 21:36:32.095 20631-20631/com.themsg.chat w/system.err: @ android.view.windowmanagerglobal.addview(windowmanagerglobal.java:266) 02-25 21:36:32.095 20631-20631/com.themsg.chat w/system.err: @ android.view.windowmanagerimpl.addview(windowmanagerimpl.java:69) 02-25 21:36:32.095 20631-20631/com.themsg.chat w/system.err: @ android.app.dialog.show(dialog.java:286)
here code:
holder.tvm.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { try { chatroommembers = getitem(position); toast.maketext(getcontext(), "here", toast.length_long).show(); new alertdialog.builder(v.getcontext()) .settitle("title") .setmessage("do want whatever?") .seticon(android.r.drawable.ic_dialog_alert) .setpositivebutton(android.r.string.yes, new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int whichbutton) { deleteuserfromchatrrom(chatroommembers.getid(), sessiondata.getinstance().getcurrentchatroom(), position); }}) .setnegativebutton(android.r.string.no, null).show(); } catch (exception e) { e.printstacktrace(); } } });
in class customadapter declare variable mcontext , arraylist data listview
arraylist<string> datasource; context mcontext;
create constructor:
public adapteraudio(context mcontext, arraylist<string> data) { super(); this.datasoure = data; this.mcontext = mcontext; }
when call customadapter activity, "activity_main.this" context need
customadapter adapter = new customadapter(activity_main.this, listaudio_hienthi10);
now have context, use variable mcontext declared replace
"getcontext()", "v.getcontext()"
now can toast or show dialog when click button in customadapter want. enjoy code!
Comments
Post a Comment