Leaving aside the lamentable wording of the documentation for this
method, it's not really acting as I hoped for an ImageView. I call
toggle() from the onClick method of the view but the view system does
not redraw my drawable with the checked state. However, if I
initialize CHECKED_STATE_SET with android.R.attr.state_checked then
the view is draw with the checked state.
So apparently my call to setImageState is not updating the state of
the ImageView. The documentation for setImageState is totally blank in
the case of an ImageView. What does this mean?
Here's my code:
private static final int[] CHECKED_STATE_SET =
{android.R.attr.state_empty};
@Override
public boolean isChecked() {
int[] ds = getDrawableState();
return ds[checkedItemIndex] ==
android.R.attr.state_checked;
}
@Override
public void setChecked(boolean isChecked) {
int[] ds = getDrawableState();
if( isChecked ) {
ds[checkedItemIndex]=android.R.attr.state_checked;
} else {
ds[checkedItemIndex]=android.R.attr.state_empty;
}
setImageState(ds,false);
refreshDrawableState();
}
@Override
public void toggle() {
setChecked( !isChecked() );
}
@Override
public int[] onCreateDrawableState(int extraSpace) {
int[] drawableState =
super.onCreateDrawableState(extraSpace +
CHECKED_STATE_SET.length );
checkedItemIndex = drawableState.length -
CHECKED_STATE_SET.length;
mergeDrawableStates( drawableState , CHECKED_STATE_SET
);
return drawableState;
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en