help
help

Reputation: 851

in android, how would you extract the image from a imagebutton?

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

Answers (2)

COD3BOY
COD3BOY

Reputation: 12112

You need to enable the drawing cache before calling the getDrawingCache() with setDrawingCacheEnabled(true).

Upvotes: 2

RajaReddy PolamReddy
RajaReddy PolamReddy

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

Related Questions