java - Pass data from dialog to activity Android -
i have problem. made method creates dialog own layout. , have no idea how pass values (strings) editext , asing variable in activity. in comments can see how trying solve this.
java method
public void makedialog(){ // custom dialog final dialog dialog = new dialog(context); dialog.setcontentview(r.layout.dialog_ip); dialog.settitle("ip connection"); // todo passing value dialog activity // final edittext ipvalueconnection = (edittext)findviewbyid(r.id.ipvalueconnection); // ipvalueconnection.setonclicklistener(this); // edittext portvalueconnection = (edittext)findviewbyid(r.id.portvalueconnection); // toast.maketext(context, ipvalueconnection.gettext().tostring(), toast.length_long).show(); button dialogbuttonlogin = (button) dialog.findviewbyid(r.id.dialogbuttonlogin); // if button clicked, close custom dialog dialogbuttonlogin.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { trytoconnect(); dialog.dismiss(); } }); // set custom dialog components - text, image , button // textview text = (textview) dialog.findviewbyid(r.id.ip); dialog.show(); }
xml layout
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content"> <imageview android:src="@drawable/antena" android:layout_width="220dp" android:layout_height="120dp" android:scaletype="centerinside" android:background="#ffffbb33" android:contentdescription="@string/app_name" android:adjustviewbounds="true" /> <edittext android:id="@+id/ipvalueconnection" 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="ip" /> <edittext android:id="@+id/portvalueconnection" 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="port"/> <button android:id="@+id/dialogbuttonlogin" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="login" android:layout_margintop="5dp" /> </linearlayout>
the error getting means reference edittext cannot found in current layout file. have find edittext in custom dialog view instead of activity view.
so instead of:
final edittext ipvalueconnection =(edittext)findviewbyid(r.id.ipvalueconnection);
use:
final edittext ipvalueconnection =(edittext)dialog.findviewbyid(r.id.ipvalueconnection);
Comments
Post a Comment