I have two Activity activity1 and activity2, activity1 has two buttons, button1 and button2. When click on button1 it should link to activity2 should have title in Action-bar has "am button1" and when click on button2 it again link to activity2 and it should have title in Action-bar has "am button2".
Any body please help me to do this.
Activity 1 class
public class ActivityOne extends Activity{
Button btnOne, btnTwo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
btnOne = (Button) findViewById(R.id.btnOne);
btnOne.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(ActivityOne.this, ActivityTwo.class);
intent.putExtra("title", "am Button1");
startActivity(intent);
}
});
btnTwo = (Button) findViewById(R.id.btnTwo);
btnOne.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(ActivityOne.this, ActivityTwo.class);
intent.putExtra("title", "am Button2");
startActivity(intent);
}
});
}
}
ActivityTwo class
public class ActivityTwo extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
String title = intent.getStringExtra("title");
getActionBar().setTitle(title);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With