Reputation: 851
I have two imagebutton and I want to switch the image of each other so button a will have button b's image while button b will have button a's image. I tried to do this in my code, but it does not work
Bitmap temmp = a1.getDrawingCache();
a1.setImageBitmap(a2.getDrawingCache());
a2.setImageBitmap(temmp);
Upvotes: 0
Views: 158
Reputation: 12112
You need to enable the drawing cache before calling the getDrawingCache()
with setDrawingCacheEnabled(true)
.
Upvotes: 2
Reputation: 22493
follow like this
buttona.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ImageButton ib = (ImageButton)v;
Drawable d11 = ib.getDrawable(); // this is the image u can get from that button
}
Upvotes: 2