1 package com.xtremelabs.robolectric.shadows; 2 3 import android.view.ViewParent; 4 import android.widget.RadioButton; 5 import android.widget.RadioGroup; 6 import com.xtremelabs.robolectric.internal.Implementation; 7 import com.xtremelabs.robolectric.internal.Implements; 8 9 /** 10 * Shadows the {@code android.widget.RadioButton} class. 11 */ 12 @SuppressWarnings({"UnusedDeclaration"}) 13 @Implements(RadioButton.class) 14 public class ShadowRadioButton extends ShadowCompoundButton { 15 16 @Implementation 17 @Override public void setChecked(boolean checked) { 18 super.setChecked(checked); 19 ViewParent viewParent = getParent(); 20 21 /* This simulates the listener a parent RadioGroup would have, listening to the 22 checked state it's child RadioButtons. Feel free to implement properly. 23 */ 24 if (viewParent instanceof RadioGroup) { 25 ((RadioGroup) viewParent).check(getId()); 26 } 27 } 28 } 29