0

I am trying to do a simple thing in my app.

There are three button that take the user to three different screen. Once the user clicks the button and comes back to the activity I want the focus to stay on the button that the user had left before.

I tried saved instance state but its not working.

oers
  • 18,436
  • 13
  • 66
  • 75
user1106888
  • 245
  • 3
  • 14
  • You could place the location of the button in the intent that you fire off to the new Activity. It's kind of a hack, but I guess it works. Why do you want/need the button to retain focus? – ahodder Jun 04 '12 at 23:11
  • @ user1106888 could this http://stackoverflow.com/questions/2459848/android-prompt-user-to-save-changes-when-back-button-is-pressed solve your query? – Santosh V M Jun 04 '12 at 23:36

1 Answers1

0

I've done the same in one of my apps.

btn1,btn2,btn3 are 3 buttons in main activity. On click of them, I'm navigating to deifferent activities.

btnenable(the red one) and btndisable(the grey one) are two images used for displaying highlighted button.


This is the snapshot: snapshot


btn1.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
    btn1.setBackgroundResource(R.drawable.btnenable);
    btn2.setBackgroundResource(R.drawable.btndisable);
    btn3.setBackgroundResource(R.drawable.btndisable);
}
});

btn2.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
    btn2.setBackgroundResource(R.drawable.btnenable);
    btn3.setBackgroundResource(R.drawable.btndisable);
    btn1.setBackgroundResource(R.drawable.btndisable);
}
});

btn3.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
    btn3.setBackgroundResource(R.drawable.btnenable);
    btn2.setBackgroundResource(R.drawable.btndisable);
    btn1.setBackgroundResource(R.drawable.btndisable);
}
});

Hope it hepls !!!
Feel free to ask your query !!

Community
  • 1
  • 1
GAMA
  • 5,958
  • 14
  • 79
  • 126