I've searched far and wide in stackoverflow but i couldnt find the answer. What would be the appropriate code for updating settext on MULTIPLE buttons when the intent string is pulled from another activity?
My mainActivity contains three buttons containing three different currencies by country. If a user clicks on one of the buttons in the mainActivity, they will go to the secondActivity where they choose another country. Once it is selected, they will go back to the mainActivity and the country that was selected should replace the default text on the button.
What happens when i do the code below is everytime i choose an option in secondActivity, all the buttons text will change the the option selected. It should only be the button that was clicked.
//mainActivity class
region1 = (Button)findViewById(R.id.region1);
region2 = (Button)findViewById(R.id.region2);
region3 = (Button)findViewById(R.id.region3);
region1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, List.class);
startActivity(i);
}
});
region2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, List.class);
startActivity(i);
}
});
region3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, List.class);
startActivity(i);
}
});
region1.setText(getIntent().getStringExtra("btn"));
region2.setText(getIntent().getStringExtra("btn"));
region3.setText(getIntent().getStringExtra("btn"));
//secondActivity class
lst_eur.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(List.this, MainActivity.class);
i.putExtra("btn", "EUR");
startActivity(i);
}
});
lst_gbp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(List.this, MainActivity.class);
i.putExtra("btn", "GBP");
startActivity(i);
}
});
lst_jpy.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(List.this, MainActivity.class);
i.putExtra("btn", "JPY");
startActivity(i);
}
});
- In mainActivity, I click region1
- Then it takes me to secondActivity
- I click lst_eur
- It takes me back to mainActivity with region1 updated from lst_eur intent
region2 and region3 should not be changed and will only be changed if it goes through similar process above.