title: Android: Selecting an Image from sdcard and displaying it in Fragment
body: <p>I'm working with fragments (API 4.1) and I want to let the user press a button, access his/her gallery, select an image, and have that image display an imageview on the original fragment where the button appeared.  I'm using the following code:</p>
  
  <pre><code>public class FillBox1Frag extends Fragment {
  Button addPics, placeBox;
  ImageView imgView;
  Bitmap b;
  Uri photoUri;
  LinearLayout fillBoxLayout;
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      if (container == null) {
          return null;
      }
  
      fillBoxLayout = (LinearLayout) inflater.inflate(R.layout.fillbox1_frag,
              container, false);
      newBin = new Bin();
      addPics = (Button) fillBoxLayout.findViewById(R.id.bPics);
      imgView = (ImageView) fillBoxLayout.findViewById(R.id.imageView1);
      addPics.setOnClickListener(new View.OnClickListener() {
  
          public void onClick(View v) {
              // TODO Auto-generated method stub
  
              Intent picChooser = new Intent(Intent.ACTION_GET_CONTENT,
                      MediaStore.Images.Media.INTERNAL_CONTENT_URI);
              picChooser.setType("image/*");
              startActivityForResult(picChooser, 12345);
          }
      });
      return fillBoxLayout;
  }
  
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
      // TODO Auto-generated method stub
      super.onActivityResult(requestCode, resultCode, data);
  
      switch (requestCode) {
      case 12345:
          if (resultCode == 12345) {
              photoUri = data.getData();
              String[] filePathColumn = { MediaStore.Images.Media.DATA };
              Cursor cursor = FillBox1Frag.this.getActivity()
                      .getContentResolver()
                      .query(photoUri, filePathColumn, null, null, null);
              cursor.moveToFirst();
              int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
              String filePath = cursor.getString(columnIndex);
              cursor.close();
              b = BitmapFactory.decodeFile(filePath);
              imgView.setImageBitmap(b);
          }
      }
  }
  </code></pre>
  
  <p>I access the Gallery, but upon selection, it just returns to the original fragment and doesn't display the image.  Here's my XML:</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/fillbox"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:tag="fillbox" &gt;
  
  &lt;Button
      android:id="@+id/bPics"
      android:layout_width="100dp"
      android:layout_height="100dp"
      android:layout_alignParentBottom="true"
      android:layout_centerHorizontal="true"
      android:layout_marginBottom="89dp"
      android:background="@drawable/buttonpics" /&gt;
  
  &lt;ImageView
      android:id="@+id/imageView1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>I've found plenty of answers dealing with a similar question, but nothing that has been able to help me with how to create this process using fragments.  Any ideas on how to get my selected image to appear in the ImageView?  Thanks for the help!</p>