[android-developers] RadioButton setChecked not working on configuration change
Hello, I am trying to set a RadioButton as checked/not checked through
code. It is working the first time I set it, but the second time, the
code does not set the button. Here is the relevant part of my code. I
have commented on the problematic part.
private boolean val;
@Override
protected void onCreate(Bundle savedInstanceState) {
// after orientation change, get the value
final Object obj = getLastNonConfigurationInstance();
if (null != obj) {
val = (boolean)obj;
}
init();
}
private void init() {
RadioButton rb = (RadioButton) findViewById(R.id.rb);
//This is working the first time init() called. But second time its
called on configuration change, not working.
rb.setChecked(val);
}
@Override
public Object onRetainNonConfigurationInstance() {
return val;
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home