title: Android: How to make user selected images become the image of the ImageButton?
body: <p>I'm new to android and I need the image from the users choice after choosing the image from any location to be the image of the image button. Can anyone provide me with a sample code to help me out? Thanks.</p>
  
  <pre><code>/** Called when the activity is first created. */
  
  @Override
  
  public void onCreate(Bundle savedInstanceState) {
  
      super.onCreate(savedInstanceState);
  
      setContentView(R.layout.file_explorer);
  
      myPath = (TextView)findViewById(R.id.action_settings);
  
      getDir(root);
  
  }
  
  
  
  private void getDir(String dirPath)
  
  {
  
   myPath.setText("Location: " + dirPath);
   item = new ArrayList&lt;String&gt;();
   path = new ArrayList&lt;String&gt;();
  
  
  
   File f = new File(dirPath);
  
   File[] files = f.listFiles();
  
  
  
   if(!dirPath.equals(root))
  
   {
    item.add(root);
    path.add(root);
  
    item.add("../");
    path.add(f.getParent());
  
   }
  
  
  
   for(int i=0; i &lt; files.length; i++)
  
   {
  
     File file = files[i];
     path.add(file.getPath());
     if(file.isDirectory())
      item.add(file.getName() + "/");
     else
      item.add(file.getName());
  
   }
  
   ArrayAdapter&lt;String&gt; fileList =
    new ArrayAdapter&lt;String&gt;(this, R.layout.file_row, item);
   setListAdapter(fileList);
  
  }
     protected void onListItemClick(ListView l, View v, int position, long id, String[]       writeinfo, Options options) {
  
   File file = new File(path.get(position)); 
  
   if (file.isDirectory())
    {
   if(file.canRead())
   getDir(path.get(position));
   else
   {
   new AlertDialog.Builder(this)
   .setTitle("[" + file.getName() + "] folder can't be read!")
   .setPositiveButton("OK", 
     new DialogInterface.OnClickListener() {
  
  
  
     @Override
     public void onClick(DialogInterface dialog, int which) {
      // TODO Auto-generated method stub
     }
    }).show();
   }
  }
  
  else
  
  {
  
   new AlertDialog.Builder(this)
  .setIcon(R.drawable.mufc)
  .setTitle("[" + file.getName() + "]")
  .setPositiveButton("OK", 
   new DialogInterface.OnClickListener() {
  
  
  
     @Override
  
   public void onClick(DialogInterface dialog, int which) {
  
      // TODO Auto-generated method stub
      }
    }).show();
    }         
   }
  }
  </code></pre>
  
  <p>Another thing, I am also not sure of how to save the image. Thanks.</p>