title: How to list directories or files in android?
body: <p>I am trying to create an Android app that can select file/s in Android phone and upload it to a server. When I click "upload" button, I want my app to display all the files and folders stored in the phone, so user can select the files to upload. I want to display it like in the Dropbox app. In Dropbox app, when user click "Upload here"->"Other Files", it will show the files and folders in Android internal storage (or external storage??Not sure about this). I wish I could show the screenshot, but I don't have enough reputation to post image.</p>
  
  <p>This is what I've done so far, but it doesn't show similar result. </p>
  
  <pre><code>private void getDir(String dirPath){
      pathTitle.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());
      }
  
      //File[] files = f.listFiles();
      if(files != null){
          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.row, item);
      setListAdapter(fileList);
  }
  </code></pre>
  
  <p>Could anyone guide me through this? I am still newbie in Android app development.</p>
  
  <p>Thanks</p>