Android Custom dialog box -
i have button, when click button open dialog box. in dialog box 1 edittext , ok button, enter text, when click ok button in text displaying.
don't know how that, me
use below
import android.app.activity; import android.app.alertdialog; import android.content.context; import android.content.dialoginterface; import android.os.bundle; import android.view.layoutinflater; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; import android.widget.edittext; public class mainactivity extends activity { final context context = this; private button button; private edittext result; public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); // components main.xml button = (button) findviewbyid(r.id.buttonprompt); result = (edittext) findviewbyid(r.id.edittextresult); // add button listener button.setonclicklistener(new onclicklistener() { @override public void onclick(view arg0) { // prompts.xml view layoutinflater li = layoutinflater.from(context); view view= li.inflate(r.layout.prompts, null); alertdialog.builder alertdialogbuilder = new alertdialog.builder( context); // set prompts.xml alertdialog builder alertdialogbuilder.setview(view); final edittext userinput = (edittext) view .findviewbyid(r.id.edittextdialoguserinput); // set dialog message alertdialogbuilder .setcancelable(false) .setpositivebutton("ok", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog,int id) { // user input , set result // edit text result.settext(userinput.gettext()); } }) .setnegativebutton("cancel", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog,int id) { dialog.cancel(); } }); // create alert dialog alertdialog alertdialog = alertdialogbuilder.create(); // show alertdialog.show(); } }); }
}
Comments
Post a Comment