Skip to content Skip to sidebar Skip to footer

Android: Set Text View's Text From Another Activity Not Working

I have 2 activities and 2 classes. In my Main class, when i click submit button it will start another activity. here is the code. public void onClick(View v) { startActivity(ne

Solution 1:

You should pass the data like this.

MainActivity.java

Intent intent = newIntent(MainActivity.this, NewActivity.class));
intent.putExtra("firstName",fvalue);
intent.putExtra("lastname",lname);
......
startActivity(intent);

NewActivity.java

@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layoutname);
    Intentintent= getIntent();
    StringfirstName= intent.getStringExtra("firstName");
    StringlastName= intent.getStringExtra("lastname");
}

Post a Comment for "Android: Set Text View's Text From Another Activity Not Working"