Android 通过选中多个复选框,从复选框图像访问ImageView的scr

Android 通过选中多个复选框,从复选框图像访问ImageView的scr,android,android-imageview,android-checkbox,Android,Android Imageview,Android Checkbox,我试图通过访问复选框中的图像源来更改ImageView中的图像。这是我的xml代码的一部分 <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/myimage" android:id="@+id/img"/> <CheckBox android:layout_width="wra

我试图通过访问复选框中的图像源来更改ImageView中的图像。这是我的xml代码的一部分

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/myimage"
    android:id="@+id/img"/>
<CheckBox
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:drawableRight="@drawable/image1"
     android:id="@+id/q4op1"/>
<CheckBox
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:drawableRight="@drawable/images2"
     android:id="@+id/q4op2"/>
<CheckBox
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:drawableRight="@drawable/images"
    android:id="@+id/q4op3"/>
<CheckBox
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:drawableRight="@drawable/download"
    android:id="@+id/q4op4"/>

我想检查复选框是否被选中。如果选中,则该复选框的drawableRight中的图像应显示在ImageView中


您能指导我如何为此编写java代码吗?

我想这可能会解决您的问题。下面的代码将为您提供所有的绘图功能

Drawable[] drawables = textView.getCompoundDrawables();
现在,如果你想比较,你可以使用

Bitmap bmp1 = ((BitmapDrawable)drawables[1] ).getBitmap();
Bitmap bmp2 = ((BitmapDrawable)getResources().getDrawable(R.drawable.twt_hover)).getBitmap();

if(bmp1 == bmp2)
{
   //Code block
}

就你而言

// Left(0), top(1), right(2), bottom(3) drawables.
// This is the right drawable.
Drawable rightCompoundDrawable = drawables[2];
用于检查复选框是否已选中

cb = (CheckBox) rowView.findViewById(R.id.q4op1); 
if(cb.isChecked()) {
  // do your drawable task here
}

cb=(复选框)rowView.findviewbyd(R.id.checkbox1);如果(cb.isChecked()){….}
是的,先生,我知道关于isChecked函数的这一点,但是如何从特定的复选框访问图像的引用您的意思是您有多个图像?对于每个复选框,确定哪个是哪个?是的,先生,图像位于每个复选框的右侧,但在XML布局中有一个imageview。或者具有多个不同ID,例如image1、image2。。。或者动态添加它们。