Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to pick the files from folders and subfolders in Android iteratively?
    primarykey
    data
    text
    <p>I am developing an app in which I am generating the list of all mp3 files and adding it in a custom list. I have a program for this but the problem is that it doesn't return the files inside the subfolder.</p> <p>Can anyone advise me or give a link or something so that I can do it iteratively? I want to do it iteratively because if I don't do so, I will have to pass a lot of information between methods and it will become really confusing. I tried doing that and ended up totally confused. </p> <p>Here is the code:</p> <pre><code>public class FragmentSongs extends Fragment { private static final String Sd_Path=new String("/sdcard/"); private MediaPlayer mp =new MediaPlayer(); @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_a, container, false); ListView SngList = (ListView) view.findViewById(R.id.SongList); ArrayList&lt;SongDetails&gt; Songinfo; // AdapterView.AdapterContextMenuInfo info; Songinfo = new ArrayList&lt;SongDetails&gt;(); File f=new File("/sdcard/"); File[] files = f.listFiles(new Mp3Filter()); if( files.length&gt;0) { for(int i=0; i&lt;files.length; i++) {SongDetails detail=new SongDetails(); detail.setIcon(R.drawable.ic_launcher); detail.setSong(files[i].getName()); detail.setArtist(files[i].getName()); detail.setAlbum(files[i].getName()); Songinfo.add(detail); } SngList.setAdapter(new CustomAdapter(Songinfo )); } else if (files.length == 0) return null; return view; } } class Mp3Filter implements FilenameFilter{ public boolean accept(File dir,String name) { return (name.endsWith(".mp3"))|| (name.endsWith(".Mp3")) ||(name.endsWith(".MP3"));//searching for the files } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload