0

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

bharathi
  • 6,019
  • 23
  • 90
  • 152

2 Answers2

2

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?

Community
  • 1
  • 1
Labeeb Panampullan
  • 34,521
  • 28
  • 94
  • 112
0

Or you can use

public void setImageResource (int resId);

method of ImageView class.

Kiril Kirilov
  • 11,167
  • 5
  • 49
  • 74