android - How to acces EditText value from AlertDialog Builder from another layout? -
i have code in config activity , dialog activated when press add_count textview, problem seems value on get_cont null, maybe because inflater doesn't work right ? (usernames , passwords arraylists)
add_cont.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { alertdialog.builder builder = new alertdialog.builder(config.this); layoutinflater inflater = config.this.getlayoutinflater(); final view dialog_layout = inflater.inflate(r.layout.dialog_add_cont, null); builder.settitle("add cont."); builder.setview(inflater.inflate(r.layout.dialog_add_cont, null)) .setpositivebutton(r.string.create_cont, new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int id) { edittext get_cont = (edittext)dialog_layout.findviewbyid(r.id.username); edittext get_pass = (edittext)dialog_layout.findviewbyid(r.id.password); string test_cont = get_cont.gettext().tostring(); string text_pass = getpass.gettext().tostring(); usernames.add(3, get_cont.gettext().tostring()); passwords.add(3, get_pass.gettext().tostring()); } }) .setnegativebutton(r.string.cancel_cont, new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int id) { dialog.cancel(); } }); alertdialog alertdialog = builder.create(); alertdialog.show(); } }); and dialog_add_cont layout looks this:
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content"> <edittext android:id="@+id/username" android:inputtype="textemailaddress" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margintop="16dp" android:layout_marginleft="4dp" android:layout_marginright="4dp" android:layout_marginbottom="4dp" android:hint="username" /> <edittext android:id="@+id/password" android:inputtype="textpassword" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margintop="4dp" android:layout_marginleft="4dp" android:layout_marginright="4dp" android:layout_marginbottom="16dp" android:fontfamily="sans-serif" android:hint="password"/> did got code somewhere wrong ?
you inflating dialog_layout , never using since inflating xml again , setting directly dialog.
your code should this:
alertdialog.builder builder = new alertdialog.builder(config.this); layoutinflater inflater = configurare.this.getlayoutinflater(); final view dialog_layout = inflater.inflate(r.layout.dialog_add_cont, null); builder.settitle("add cont."); builder.setview(dialog_layout) ....
Comments
Post a Comment