I'm writing an application for Android and I have difficulties with change the Buttons background. I have four Activities, Activity1 is a TableLayout where I have three Buttons. Every Button opens another Activity. I'd like to change the Button in Activity1 from Activity2. So I tried to do it with passing a Result. In Activity2 I set a Result like this:
@Override
public void onClick(View v) {
setResult(Activity1.RESULT_OK);
finish();
}
}
In Activity1 I have this code:
protected void onActivityResult(int requestCode, int resultCode, Intent data){
if (resultCode == RESULT_OK)
button1.setBackgroundResource(R.drawable.image);
}
So when the user click the Button in the Activity2 then in the Activity1 the Button change the background. My problem is that I can do that only once and I have to do that two more times in the other Activities. I tried to do RESULT_OK2 but it shows me error. So how can I do it more times? I tried to change the background another way. In Activity2 I used the button1 which is in Activity1 but I then I got NullPointerExeption. If anyone has an idea how to that please response!