android - Editext (Dialog) Value is empty? -
i try use edittext
in dialog
. use sample developer.android.com (http://developer.android.com/guide/topics/ui/dialogs.html). want value
of edittext when press positive button
.
code
public dialog oncreatedialog() { alertdialog.builder builder = new alertdialog.builder(main_list.this); // layout inflater final layoutinflater inflater = main_list.this.getlayoutinflater(); builder.setview(inflater.inflate(r.layout.serie_add, null)) // add action buttons .setpositivebutton(r.string.search, new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int id) { view promptsview = inflater.inflate(r.layout.serie_add, null); final edittext userinput = (edittext) promptsview .findviewbyid(r.id.series); intent intent = new intent(); intent.setclass(main_list.this, add_series.class); intent.putextra("name", userinput.gettext()); startactivity(intent); } }) .setnegativebutton(r.string.cancel, new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int id) { } }); return builder.create(); }
rewrite code as:
public dialog oncreatedialog() { alertdialog.builder builder = new alertdialog.builder(main_list.this); // layout inflater final layoutinflater inflater = main_list.this.getlayoutinflater(); view view = inflater.inflate(r.layout.serie_add, null); final edittext userinput = (edittext) view .findviewbyid(r.id.series); builder.setview(view) // add action buttons .setpositivebutton(r.string.search, new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int id) { view promptsview = inflater.inflate(r.layout.serie_add, null); intent intent = new intent(); intent.setclass(main_list.this, add_series.class); intent.putextra("name", userinput.gettext().tostring()); startactivity(intent); } }) .setnegativebutton(r.string.cancel, new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int id) { } }); return builder.create(); }
Comments
Post a Comment