java - Can't set values in second activity -
so i'm making simple application takes information user i.e name, address etc , puts in the textviews in next activity when put in values , move next activity there's nothing displayed in textviews.
here's first activity
public class mainactivity extends activity { public string name; public string age; public string address; public string city; public string phoneno; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); edittext name = (edittext) findviewbyid(r.id.edittext1); name = name.gettext().tostring(); edittext amge = (edittext) findviewbyid(r.id.agee); age = amge.gettext().tostring(); edittext address2 = (edittext) findviewbyid(r.id.address); address = address2.gettext().tostring(); edittext city2 = (edittext) findviewbyid(r.id.city); city = city2.gettext().tostring(); edittext phone2 = (edittext) findviewbyid(r.id.phone); phoneno = phone2.gettext().tostring(); final imageview d = (imageview) findviewbyid(r.id.done); d.setonclicklistener(new onclicklistener(){ @override public void onclick(view v) { // todo auto-generated method stub intent intent = new intent(mainactivity.this, second.class); startactivity(intent); } }); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); if (id == r.id.action_settings) { return true; } return super.onoptionsitemselected(item);}}
here's second activity
public class second extends mainactivity { protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.second); textview n1 = (textview) findviewbyid(r.id.name1); n1.settext(name); textview a1 = (textview) findviewbyid(r.id.age1); a1.settext(age); textview ad1 = (textview) findviewbyid(r.id.address1); ad1.settext(address); textview c1 = (textview) findviewbyid(r.id.city1); c1.settext(city); textview p1 = (textview) findviewbyid(r.id.phone1); p1.settext(phoneno);} public static void main(string[] args) { // todo auto-generated method stub }}
here's xml main activity
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" android:orientation="horizontal" android:background="@drawable/bg" tools:context="com.example.randomtests.mainactivity" > <textview android:id="@+id/textview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" android:layout_weight="1" android:textsize="21dp" android:textcolor="#ffffff" android:text="please enter required info" android:textappearance="?android:attr/textappearancelarge" /> <imageview android:id="@+id/imageview1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margintop="15dp" android:layout_centerhorizontal="true" android:layout_below="@+id/textview1" android:src="@drawable/bar" /> <edittext android:id="@+id/address" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/agee" android:layout_below="@+id/agee" android:layout_margintop="14dp" android:ems="10" android:hint="@string/address" android:inputtype="textpostaladdress" android:textcolor="#000000" /> <edittext android:id="@+id/city" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/address" android:layout_below="@+id/address" android:layout_margintop="17dp" android:ems="10" android:hint="@string/city" android:textcolor="#000000" /> <edittext android:id="@+id/edittext1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_aligntop="@+id/imageview1" android:layout_centerhorizontal="true" android:layout_margintop="33dp" android:ems="10" android:gravity="top" android:textcolor="#000000" android:hint="@string/namu" android:inputtype="textpersonname" /> <edittext android:id="@+id/agee" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/edittext1" android:layout_below="@+id/edittext1" android:layout_margintop="14dp" android:ems="10" android:hint="@string/age" android:inputtype="phone" android:textcolor="#000000" /> <edittext android:id="@+id/phone" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/city" android:layout_below="@+id/city" android:layout_margintop="15dp" android:ems="10" android:hint="@string/phone" android:inputtype="phone" android:textcolor="#000000" /> <imageview android:id="@+id/done" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignright="@+id/textview1" android:layout_below="@+id/phone" android:layout_marginright="14dp" android:layout_margintop="12dp" android:src="@drawable/button" />
here's xml second activity
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/bg" > <textview android:id="@+id/info1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparenttop="true" android:textcolor="#ffffff" android:textsize="33dp" android:layout_centerhorizontal="true" android:text="@string/yourinfo" android:textappearance="?android:attr/textappearancelarge" /> <textview android:id="@+id/name1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_below="@+id/info1" android:textcolor="#ffffff" android:layout_marginleft="19dp" android:layout_margintop="26dp" android:textappearance="?android:attr/textappearancemedium" /> <textview android:id="@+id/age1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignright="@+id/name1" android:layout_below="@+id/name1" android:textcolor="#ffffff" android:layout_margintop="20dp" android:textappearance="?android:attr/textappearancemedium" /> <textview android:id="@+id/address1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignright="@+id/age1" android:layout_below="@+id/age1" android:textcolor="#ffffff" android:layout_margintop="20dp" android:textappearance="?android:attr/textappearancemedium" /> <textview android:id="@+id/city1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignright="@+id/address1" android:layout_below="@+id/address1" android:textcolor="#ffffff" android:layout_margintop="20dp" android:textappearance="?android:attr/textappearancemedium" /> <textview android:id="@+id/phone1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignright="@+id/city1" android:layout_below="@+id/city1" android:textcolor="#ffffff" android:layout_margintop="20dp" android:textappearance="?android:attr/textappearancemedium" />
after declare intent , try sending data this
//this use key-value intent.putextra("user_name" , "your string"); intent.putextra("user_age" , "your string");
and etc.
and other activity try use
bundle = getintent().getextras(); string username = extra.getstring("user_name"); string userage = extra.getstring("user_age");
Comments
Post a Comment