Give an example of code in which an event handler in a Button one Activity would change a TextView in another Activity .

Here is my handler:

 String data = "This is the best day"; @Override public void onClick(View view) { Intent intent; switch (view.getId()) { case R.id.button: intent = new Intent(this, Main2Activity.class); intent.putExtra("man", data.toString()); startActivity(intent); break; } }} 
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

2 answers 2

In Main2Activity.class:

  TextView txt_1 = (TextView) findViewById(R.id.myTxtView); txt_1.setText(getIntent().getStringExtra("man")); 

    In the second activity :

     Intent intent = getIntent(); String data = intent.getStringExtra("man");