无法解析方法 'setImageResource'(android.graphics.drawable.Drawable)
Cannot resolve method 'setImageResource'(android.graphics.drawable.Drawable)
我正在尝试更改我的 ImageButton 的来源,但由于某种原因我不断收到此错误消息:无法解析方法 'setImageResource' (android.graphics.drawable.Drawable)。
这是我正在尝试使用的代码:
<ImageButton
android:layout_width="32dp"
android:layout_height="32dp"
android:id="@+id/cuenta_1"
android:text="cuenta1"
android:background="@mipmap/ic_fondo"
android:layout_toLeftOf="@id/agregarCuenta"/>
并且在 mainActivity 中:
Drawable logo = new BitmapDrawable(bitmap);
findViewById(R.id.cuenta_2).setImageResource(logo);
知道如何解决这个问题吗?
我可以看到 2 个错误
改变
findViewById(R.id.cuenta_2).setImageResource(logo);
至
// Create and cast an object of type ImageButton, with the proper id
ImageButton imb = (ImageButton) findViewById(R.id.cuenta_1); // you were trying to find cuenta_2, which is not in the layout
imb.setImageResource(R.drawables.some_image); // setImageResource takes an int, not a drawable.
供您参考:http://developer.android.com/reference/android/widget/ImageView.html#setImageResource%28int%29
我正在尝试更改我的 ImageButton 的来源,但由于某种原因我不断收到此错误消息:无法解析方法 'setImageResource' (android.graphics.drawable.Drawable)。
这是我正在尝试使用的代码:
<ImageButton
android:layout_width="32dp"
android:layout_height="32dp"
android:id="@+id/cuenta_1"
android:text="cuenta1"
android:background="@mipmap/ic_fondo"
android:layout_toLeftOf="@id/agregarCuenta"/>
并且在 mainActivity 中:
Drawable logo = new BitmapDrawable(bitmap);
findViewById(R.id.cuenta_2).setImageResource(logo);
知道如何解决这个问题吗?
我可以看到 2 个错误
改变
findViewById(R.id.cuenta_2).setImageResource(logo);
至
// Create and cast an object of type ImageButton, with the proper id
ImageButton imb = (ImageButton) findViewById(R.id.cuenta_1); // you were trying to find cuenta_2, which is not in the layout
imb.setImageResource(R.drawables.some_image); // setImageResource takes an int, not a drawable.
供您参考:http://developer.android.com/reference/android/widget/ImageView.html#setImageResource%28int%29