I have three different classes and when the ImageButton
in class1 is clicked I want that the TextView
in class3 should change to "50". On the other hand when the ImageButton
in class2 is clicked I want that the TextView in class3 should change to "0".
class1:
ImageButton button1 = (ImageButton) this.findViewById(R.id.imageButton);
if (button1 != null) {
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent passdata_intent1 = new Intent(class1.this, class3.class);
String data1 = "50";
Bundle bundle1 = new Bundle();
bundle1.putString("firstdata", data1);
passdata_intent1.putExtras(bundle1);
startActivity(passdata_intent1);
}
});
}
class2:
ImageButton button1 = (ImageButton) this.findViewById(R.id.imageButton);
if (button1 != null) {
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent passdata_intent2 = new Intent(class2.this, class3.class);
String data2 = "0";
Bundle bundle2 = new Bundle();
bundle2.putString("seconddata", data2);
passdata_intent2.putExtras(bundle2);
startActivity(passdata_intent2);
}
});
}
class3:
TextView score = (TextView) findViewById(R.id.textViewscore);
Bundle bundle1 = getIntent().getExtras();
String data_1 = bundle1.getString("firstdata");
score.setText(data_1);
Bundle bundle2 = getIntent().getExtras();
String data_2 = bundle2.getString("seconddata");
score.setText(data_2);
So my problem is that when I start the application and I click on the ImageButton
in class2 the TextView
in class3 changes. But when I click the ImageButton
in class1 nothing changes in class3.