How To Pick Image From Gallery in Android App
<p>i am trying to make an app in android that integrate Image Gallery with my app.<br>
Following are the tasks my app dose :</p>

<p>1.First screen shows user with and Image view and a button to load Picture.<br>
2.On click of “Load Picture” button, user will be redirected to Android’s Image Gallery where she can select one image.<br>
3.Once the image is selected, the image will be loaded in Image view on main screen.</p>

<p>in addition to  these three above mentioned tasks i need my app to perform following tasks :</p>

<p>4.When the image is selected ,it is shown on main screen , when i go for more "load picture" option the previously selected image get disappeared ,but i need my app not to hide the previously selected image ,infact the all selected images it shows in a horizontally scrolling list on the main screen .and when i select any of them from a horizontal scrolling list they shown on the main screen .</p>

<p>for this my xml code is :</p>

<p><strong>main.xml :</strong></p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"&gt;
    &lt;ImageView
        android:id="@+id/imgView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"&gt;&lt;/ImageView&gt;
    &lt;Button
        android:id="@+id/buttonLoadPicture"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:text="Load Picture"
        android:layout_gravity="center"&gt;&lt;/Button&gt;
&lt;/LinearLayout&gt;
</code></pre>

<p><strong>java code :</strong></p>

<pre><code>package com.ohile.imagegallerydemo;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class ImageGallery extends Activity {

    private static int RESULT_LOAD_IMAGE = 1;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_image_gallery);

        Button buttonLoadImage = (Button) findViewById(R.id.buttonLoadPicture);
        buttonLoadImage.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {

                Intent i = new Intent(
                        Intent.ACTION_PICK,
                        android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

                startActivityForResult(i, RESULT_LOAD_IMAGE);
            }
        });
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == RESULT_LOAD_IMAGE &amp;&amp; resultCode == RESULT_OK &amp;&amp; null != data) {
            Uri selectedImage = data.getData();
            String[] filePathColumn = { MediaStore.Images.Media.DATA };

            Cursor cursor = getContentResolver().query(selectedImage,
                    filePathColumn, null, null, null);
            cursor.moveToFirst();

            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            String picturePath = cursor.getString(columnIndex);
            cursor.close();

            ImageView imageView = (ImageView) findViewById(R.id.imgView);
            imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));

        }


    }
}
</code></pre>
