3434 * The item view for each item in the ListView-based MenuViews.
3535 */
3636public class ListMenuItemView extends LinearLayout implements MenuView .ItemView {
37+ private static final String TAG = "ListMenuItemView" ;
3738 private MenuItemImpl mItemData ;
3839
3940 private ImageView mIconView ;
@@ -121,27 +122,25 @@ public MenuItemImpl getItemData() {
121122 }
122123
123124 public void setCheckable (boolean checkable ) {
124-
125125 if (!checkable && mRadioButton == null && mCheckBox == null ) {
126126 return ;
127127 }
128128
129- if (mRadioButton == null ) {
130- insertRadioButton ();
131- }
132- if (mCheckBox == null ) {
133- insertCheckBox ();
134- }
135-
136129 // Depending on whether its exclusive check or not, the checkbox or
137130 // radio button will be the one in use (and the other will be otherCompoundButton)
138131 final CompoundButton compoundButton ;
139132 final CompoundButton otherCompoundButton ;
140133
141134 if (mItemData .isExclusiveCheckable ()) {
135+ if (mRadioButton == null ) {
136+ insertRadioButton ();
137+ }
142138 compoundButton = mRadioButton ;
143139 otherCompoundButton = mCheckBox ;
144140 } else {
141+ if (mCheckBox == null ) {
142+ insertCheckBox ();
143+ }
145144 compoundButton = mCheckBox ;
146145 otherCompoundButton = mRadioButton ;
147146 }
@@ -155,12 +154,12 @@ public void setCheckable(boolean checkable) {
155154 }
156155
157156 // Make sure the other compound button isn't visible
158- if (otherCompoundButton .getVisibility () != GONE ) {
157+ if (otherCompoundButton != null && otherCompoundButton .getVisibility () != GONE ) {
159158 otherCompoundButton .setVisibility (GONE );
160159 }
161160 } else {
162- mCheckBox .setVisibility (GONE );
163- mRadioButton .setVisibility (GONE );
161+ if ( mCheckBox != null ) mCheckBox .setVisibility (GONE );
162+ if ( mRadioButton != null ) mRadioButton .setVisibility (GONE );
164163 }
165164 }
166165
0 commit comments