嗨,我正在扭动一个可检查的 gridView 及其工作。但不是它的意图(像往常一样)一切都像我想要的那样工作,除了在绘制复选框时存在延迟。
网格将变为真实,但图像不会绘制,直到我检查另一个网格。取消检查虚假陈述也是如此。
这可能是一件非常简单和愚蠢的事情,但我觉得我盯着它有点盲目。许多坦克。
public class CheckableImageView extends ImageView implements Checkable {
private boolean mChecked=false;
public CheckableImageView(final Context context,
final AttributeSet attrs) {
super(context, attrs);
}
@Override
public void toggle() {
setChecked(!mChecked);
Toast.makeText(getBaseContext(), "toggle "+mChecked, Toast.LENGTH_SHORT)
.show();
}
@Override
public boolean isChecked() {
Toast.makeText(getBaseContext(), "checked", Toast.LENGTH_SHORT)
.show();
return mChecked;
}
@Override
public void setChecked(final boolean checked) {
if (mChecked == checked)
return;
mChecked = checked;
refreshDrawableState();
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if(mChecked) {
Bitmap check = BitmapFactory.decodeResource(
getResources(), R.drawable.cecked);
canvas.drawBitmap(check, 0,0, new Paint());
}
}
适配器///////////////////////////////////////////////// ///////////////7
public class ImageAdapter extends BaseAdapter {
private Context context;
public ImageAdapter(Context c) {
context = c;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
// return randomList.size();
return 12;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
CheckableImageView imageView;
if (convertView == null) {
imageView = new CheckableImageView(context, null);
imageView.setLayoutParams(new GridView.LayoutParams(240, 240));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(5, 5, 5, 5);
} else {
imageView = (CheckableImageView) convertView;
}
imageView.setImageResource(randomList.get(position));
return imageView;
}
}
OnItemClick/////////////////////////////////////
@Override
public void onItemClick(AdapterView parent, View v, int position,
long id) {
cv = (CheckableImageView) v;
cv.toggle();
cv.refreshDrawableState();
}
});