Reputation: 121
Is there a way to reference to an EditText/Checkbox from a previous XML file? On the final page of my app I want to capture some EditText and if any Checkboxes were checked on the previous page. I get a NullPointerException everytime I use the corresponding id because they aren't in the current XML files, but the previous one. Is there any way to reference these pieces and retrieve the info from the previous page? Thank you.
Upvotes: 0
Views: 51
Reputation: 15402
Use Intent to pass data from one activity to another, you cannot directly access fields that are not there in your current view
Intent mIntent = new Intent(this, NewActivity.class);
mIntent .putExtra("CheckBox1", isChecked1);
mIntent .putExtra("CheckBox2", isChecked2);
mIntent .putExtra("stringRef", "Some more data");
startActivity(mIntent);
To recieve the values in new Activity.
Intent intent = getIntent();
if (intent != null) {
String toGetSomeData = intent.getStringExtra("stringRef");
boolean checkbox1 = intent.getBooleanExtra("CheckBox1", false); // false is default value
}
Upvotes: 2