我试图更改我的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);知道我该怎么解决这个问题吗?
发布于 2015-06-24 17:55:47
我能看到两个错误
变化
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
https://stackoverflow.com/questions/31033570
复制相似问题