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 = new Intent(MainActivity.this, NewActivity.class));
intent.putExtra("firstName",fvalue);
intent.putExtra("lastname",lname);
......
startActivity(intent);

NewActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layoutname);
    Intent intent = getIntent();
    String firstName = intent.getStringExtra("firstName");
    String lastName = intent.getStringExtra("lastname");
}

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