title: Displaying folders only containing files with certain file type
body: <p>I have set up code to display all folders that are on the SD card but now I am trying to figure out how to only display folders which contain MP3 files.</p>
  
  <p>How can I filter out the folders that don't contain .MP3 files? thanks.</p>
  
  <p>class:</p>
  
  <pre><code>public class FragmentFolders extends ListFragment {
  private File file;
  private List&lt;String&gt; myList;
  
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      myList = new ArrayList&lt;String&gt;();
  
      String root_sd = Environment.getExternalStorageDirectory().toString();
      file = new File(root_sd);
  
      File list[] = file.listFiles();
  
      for (int i = 0; i &lt; list.length; i++) {
          myList.add(list[i].getName());
      }
  
      setListAdapter(new ArrayAdapter&lt;String&gt;(getActivity(),
              android.R.layout.simple_list_item_1, myList));
  
  }
  
  public void onListItemClick(ListView l, View v, int position, long id) {
      super.onListItemClick(l, v, position, id);
  
      File temp_file = new File(file, myList.get(position));
  
      if (!temp_file.isFile()) {
          file = new File(file, myList.get(position));
          File list[] = file.listFiles();
  
          myList.clear();
  
          for (int i = 0; i &lt; list.length; i++) {
              myList.add(list[i].getName());
          }
          Toast.makeText(getActivity(), file.toString(), Toast.LENGTH_LONG)
                  .show();
          setListAdapter(new ArrayAdapter&lt;String&gt;(getActivity(),
                  android.R.layout.simple_list_item_1, myList));
  
      }
  
      return;
  }
  
  }
  </code></pre>