I have 2 xml, the name is formOne.xml and formTwo.xml
formOne.xml look like this :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp">
<EditText
android:id="@+id/editTextName"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</LinearLayout>
and fomTwo.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp">
<Button
android:id="@+id/buttonSave"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="@string/btSave" />
</LinearLayout>
and i have two activity, the name is FormOne.java and FormTwo.java
FormOne.java :
public class FormOne extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.formOne);
EditText etName = (EditText) findViewById(R.id.editTextName);
}
}
and FormTwo.java :
public class FormTwo extends Activity implements OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.formTwo);
EditText etName = (EditText) findViewById(R.id.editTextName);
Button btSave = (Button) findViewById(R.id.buttonSave);
btSimpan.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (etName.getText().length() != 0) {
Toast.makeText(FormTwo.this, "Name is : "+etName.getText().toString(), Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(FormTwo.this, "Input the name please", Toast.LENGTH_SHORT).show();
}
// TODO Auto-generated method stub
}
});
}
i want to catch value from editTextName, and value can show in FormTwo.java with Toast.
but myapplication force close,
how i can to get value editTextName, without passing data with bundle. because in FormOne.java not any button to send value editTextName.
Thanks in Advance
Save
edittextvalue intosharedpreferencesonontextchangelistener()event of edittext and get data fromsharedpreferencesinto form2 activity.