David
David

Reputation: 2721

how to change the background or the image source when a clickable imageview in android is clicked?

I set android:clickable="true" to an imageview in my android app. I want to change the background or the image source when it is clicked, how could i do that?

Upvotes: 0

Views: 408

Answers (1)

Onuray Sahin
Onuray Sahin

Reputation: 4135

Try this:

myImageView.setOnClickListener(MyOnClickHandler);

And write handler like:

OnClickListener MyOnClickHandler = new OnClickListener() {
    @Override
    public void onClick(View v) {
                 myImageView.setImageResource(R.id.imageView1);
                 myImageView.setBackgroundResource(R.id.imageView2);
                 //myImageView.setImageBitmap(bm);
                 //myImageView.setImageDrawable(R.drawable.image1);
    }
};

Upvotes: 2

Related Questions