android - how to retrieve values from popup to main? -
i have main activity
calls popup window:
addproduct.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { intent popup = new intent(singlevoucher.this, popup.class); if (additionalproduct!=null) { popup.putextra("additionalamount", additionalquantity); popup.putextra("additionalprice", additionalprice); popup.putextra("additionalproduct", additionalproduct); } startactivity(popup); } });
the popup:
public class popup extends activity { private onsubmitlistener mlistener; @override protected void oncreate (bundle savedinstancestate){ super.oncreate(savedinstancestate); requestwindowfeature(window.feature_no_title); setcontentview(r.layout.popup_window); displaymetrics dm = new displaymetrics(); getwindowmanager().getdefaultdisplay().getmetrics(dm); int width = dm.widthpixels; int height = dm.heightpixels; windowmanager.layoutparams windowmanager = getwindow().getattributes(); windowmanager.dimamount = 0.75f; getwindow().addflags(windowmanager.layoutparams.flag_dim_behind); textview submitadditional = (textview) findviewbyid(r.id.submitadditional); final edittext product = (edittext) findviewbyid(r.id.adittionaltextedit); final edittext qty = (edittext) findviewbyid(r.id.additionalquantityte); final edittext price = (edittext) findviewbyid(r.id.adittionalpricete); final intent intent = getintent(); final context context = this; submitadditional.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { string additionalproduct = product.gettext().tostring(); string additionalquantity = qty.gettext().tostring(); string additionalprice = price.gettext().tostring(); if (additionalproduct!=null && additionalprice.isempty()==false && additionalquantity.isempty()==false) { intent.putextra("additionalamount", additionalquantity); intent.putextra("additionalprice", additionalprice); intent.putextra("additionalproduct", additionalproduct); } else{ alertdialog.builder alert = new alertdialog.builder(context); alert.settitle("missing details"); alert.setmessage("some of required fields missing. please try again"); alert.setpositivebutton(android.r.string.yes, new dialoginterface.onclicklistener(){ @override public void onclick(dialoginterface dialog, int which) { } }); } } }); getwindow().setlayout((int) (width * .8), (int) (height * .3)); }
}
and xml of poup window is:
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/bluegray"> <textview android:id="@+id/additionaltitle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="12dp" android:layout_margintop="5dp" android:layout_alignparenttop="true" android:paddingtop="2dp" android:text="product name" android:textsize="18dp" android:textcolor="@color/white"> </textview> <edittext android:id="@+id/adittionaltextedit" android:layout_width="260dp" android:layout_height="50dp" android:layout_below="@+id/additionaltitle" android:background="@color/white" android:textsize="12dp" android:textcolor="@color/black" android:layout_centerhorizontal="true" android:gravity="top"> </edittext> <textview android:id="@+id/additionalquantitytv" android:layout_marginleft="12dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/adittionaltextedit" android:text="quantity" android:textcolor="@color/white" android:textsize="15dp" android:layout_margintop="5dp"> </textview> <edittext android:id="@+id/additionalquantityte" android:layout_width="100dp" android:layout_height="20dp" android:layout_torightof="@+id/additionalquantitytv" android:layout_below="@+id/adittionaltextedit" android:background="@color/white" android:layout_margintop="5dp" android:layout_alignparentright="true" android:layout_alignparentend="true" android:layout_marginright="14dp" android:layout_marginleft="38dp" android:numeric="integer" android:textsize="14dp"> </edittext> <textview android:id="@+id/adittionalpricetv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="12dp" android:layout_below="@+id/additionalquantitytv" android:text="overall price" android:textcolor="@color/white" android:textsize="15dp" android:layout_margintop="5dp"> </textview> <edittext android:id="@+id/adittionalpricete" android:layout_width="100dp" android:layout_height="20dp" android:layout_torightof="@+id/adittionalpricetv" android:layout_below="@+id/additionalquantityte" android:background="@color/white" android:layout_margintop="5dp" android:layout_alignparentright="true" android:layout_alignparentend="true" android:layout_marginright="14dp" android:layout_marginleft="10dp" android:numeric="decimal" android:textsize="14dp"> </edittext> <textview android:id="@+id/popupclose" android:layout_margintop="10dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="cancel" android:layout_below="@+id/adittionalpricete" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:layout_marginleft="14dp" android:textcolor="@color/white"> </textview> <textview android:id="@+id/submitadditional" android:layout_margintop="10dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="submit" android:layout_below="@+id/adittionalpricete" android:layout_alignparentright="true" android:layout_alignparentend="true" android:layout_marginright="14dp" android:textcolor="@color/white"> </textview> </relativelayout>
i want values edittext
, send them parent. how can send data view called popup?
you can use startactivityforresult , setresult methods achieve this. in mainactivity start popup activity this
startactivityforresult(popup,1);
in popup activity use setresult method pass value main activity.
intent intent = new intent(); intent.putextra("data",data); // data value need in parent setresult(100,data);
in mainactivity use onactivityresult method data
@override protected void onactivityresult(int requestcode, int resultcode, intent data) { value = data.getbundleextra("data");
Comments
Post a Comment