Reputation: 79
I have 2 image button. imagebutton1 has a picture on it as a background and the imagebutton2 has a blank background. how can I make that if I click the imagebutton1, the imagebutton2 will get the background picture of the imagebutton1 and if I click again the imagebutton2, the background will be blank again. just like the concept of the game "4pic 1 word" if you guys are familiar with that. thanks.
Upvotes: 0
Views: 96
Reputation: 2188
You can do it like this..
int minute = 0;
final Drawable d = img2.getDrawable();
img1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
if (minute == 0) {
img2.setImageDrawable(img1.getDrawable());
minute = 1;
} else {
img2.setImageDrawable(d);
minute = 0;
}
}
});
img2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
img2.setImageDrawable(d);
}
});
Change the click event as your requirement.Hope it helps you..
Upvotes: 1
Reputation: 679
You can use this on click of button
public void firstbutton(){
ImageView ImageButton2 = (ImageButton)findViewById(R.id.imageButton2);
ImageButton2 .setImageResource(R.drawable.image1);
}
public void Secondbutton()
ImageView ImageButton1 = (ImageButton)findViewById(R.id.imageButton1);
ImageButton2 .setImageResource(R.drawable.image2);
}
call this method on button click where you want cheers........
Upvotes: 0
Reputation: 14510
public Bitmap getBitmapFromImageView(ImageView imageView){
Drawable drawable = imageView.getDrawable();
Bitmap bitmap = null;
if (drawable instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
bitmap = bitmapDrawable.getBitmap();
}
return bitmap;
}
Upvotes: 1