bharathi
bharathi

Reputation: 6271

Android-Replace one image by another image

I am new to android.I have a image which is declared in xml file using imageView.The problem is onRuntime I want to replace that with any image from gallery when the image is long clicked.what should I have to do.Thanks in advance

Upvotes: 0

Views: 1840

Answers (2)

Kiril Kirilov
Kiril Kirilov

Reputation: 11257

Or you can use

public void setImageResource (int resId);

method of ImageView class.

Upvotes: 0

Labeeb Panampullan
Labeeb Panampullan

Reputation: 34823

You can write the code to replace your image at LongClickListener ,

imageview.setOnLongClickListener(new OnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {
                ((ImageView) v).setImageBitmap(bitmap);
                return false;
            }
        });

And to get the idea to access image form gallery, refer this how to pick a image from gallery (SD Card) for my app in android?

Upvotes: 2

Related Questions