I am trying to send parameters from one Activity to another using Intent and extras.putString(); from one activity and trying to fetch the values in another and set that value in the Textview field.
My code looks like this:
PAActivity.java
Fname = (EditText) findViewById(R.id.editFirst);
Lname = (EditText) findViewById(R.id.editLast);
email = (EditText) findViewById(R.id.editEmail);
phone = (EditText) findViewById(R.id.editPhone);
submit = (Button) findViewById(R.id.submit);
Fnameholder = Fname.getText().toString();
Lnameholder = Lname.getText().toString();
emailHolder = email.getText().toString();
phoneHolder = phone.getText().toString();
Log.e("phoneHolder",phoneHolder);
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent myIntent = new Intent(PAActivity.this,DisplayActivity.class);
Bundle extras = new Bundle();
extras.putString("F_NAME", Fnameholder);
extras.putString("L_NAME", Lnameholder);
extras.putString("EMAIL", emailHolder);
extras.putString("PHONE", phoneHolder);
myIntent.putExtras(extras);
PAActivity.this.startActivity(myIntent);
}
});
DisplayActivity.java
name = new TextView(this);
email = new TextView(this);
phone = new TextView(this);
name = (TextView) findViewById(R.id.name);
email = (TextView) findViewById(R.id.email);
phone = (TextView) findViewById(R.id.phone);
Bundle extras = getIntent().getExtras();
if (extras != null) {
first = (String) extras.get("F_NAME");
last = (String) extras.get("L_NAME");
Nameholder = "my name is "+first+" "+last;
name.setText(Nameholder);
emailHolder = (String) extras.get("EMAIL");
email.setText(emailHolder);
phoneHolder = (String) extras.get("PHONE");
phone.setText(phoneHolder);
}
The problem here is that, the intent is loading the second activity but the setText does not seem to work. I am not able to see the values being set in the Textviews. Could someone please help?