Android AlertDialog.Builder OnClickListener on custom button -
i display omn alert dialog. created layout , used on onclicklistener. (when click on element of list, displays details it)
when alertdialog appears, fine own dismiss button works. sadly doesn't , don't know how manage this.
this xml file :
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/detaildialog" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@color/popup_background" > <button android:id="@+id/dismissalert" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_aligntop="@+id/firstdivider" android:layout_centerhorizontal="true" android:background="@color/popup_background" android:text="dismiss" android:textcolor="@color/splashcolor" /> <textview android:id="@+id/alertdetail" android:layout_width="wrap_content" android:layout_height="80dp" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" android:paddingtop="20dp" android:text="description : alert's details" android:textcolor="@color/text" android:textsize="20dp" /> <view android:id="@+id/firstdivider" android:layout_width="fill_parent" android:layout_height="1dp" android:layout_alignparentleft="true" android:layout_below="@+id/alertdetail" android:background="@color/design_alert" />
and part of code
view.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { this.messagedialog("order " + string + " waiting time estimate", orderalertspage.this); } public void messagedialog(string message, final context activity) { //on instancie notre layout en tant que view layoutinflater factory = layoutinflater.from(activity); final view alertdialogview = factory.inflate(r.layout.alert_detail_dialog, null); //création de l'alertdialog final alertdialog.builder adb = new alertdialog.builder(activity); adb.setview(alertdialogview); textview text = (textview) alertdialogview.findviewbyid(r.id.alertdetail); text.setmovementmethod(scrollingmovementmethod.getinstance()); text.settext(message); text.setgravity(gravity.center); button dismiss = (button) alertdialogview.findviewbyid(r.id.dismissalert); dismiss.setonclicklistener(new onclicklistener() { public void onclick(view v) { ((dialoginterface) adb).dismiss(); // can't it.. } }); adb.show(); } });
thanks help
call dismiss()
on dialog, not builder.
for example,
final alertdialog dlg = adb.show(); // in onclick() dlg.dismiss();
Comments
Post a Comment