Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8067643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:23:33+00:00 2026-06-05T12:23:33+00:00

Can someone please point out whats going wrong here: The code below loops through

  • 0

Can someone please point out whats going wrong here:

The code below loops through the directories on the /sdcard. If it finds a file it adds the name etc to an array. If it finds a directory, it drops in and scans it.

The system.out returns all of the files on the /sdcard.

The array adapter only lists what it finds at the top level directory

On my sd card I am expecting it to return two mp3 files, one in the top level directory, one burried within the tree. The system.out line finds both.

I suspect that the fls arraylist is being destroyed. If it is, how do I go about preserving this?

Thanks in advance!

 public void fill(File f) {     
        File[]files = f.listFiles();
          List<Option>fls = new ArrayList<Option>();
          if (files != null) {
                for(File ff: files){
                    if(!ff.isDirectory())
                        {
                        /** Only Add MP3's to the list    */
                        String filename=ff.getName();
                        String ext = filename.substring(
                                    filename.lastIndexOf('.')+1, filename.length());
                                           if(ext.equals("MP3")||ext.equals("mp3")||ext.equals("Mp3")||ext.equals("mP3"))
                        fls.add(new Option(ff.getName(),"File Size: "+ff.length()/1048576 + "MB",ff.getAbsolutePath()));
                        System.out.println( ff.getName() );
                        }
                    else
                        fill(ff);
               }    
          }

        Collections.sort(fls);
        adapter = new FileArrayAdapter(getActivity(),R.layout.folder_view,fls);
        this.setListAdapter(adapter);   
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T12:23:35+00:00Added an answer on June 5, 2026 at 12:23 pm

    With the code as it is the arraylist will be recreated everytime you enter a new folder, you need to take the adapter code out of the function and have the fill function take the arraylist as a parameter so that each call will take the same arraylist.

    ie.

    List<Option>fls = new ArrayList<Option>();
    
    fill(f,fls);
    
    Collections.sort(fls);
    adapter = new FileArrayAdapter(getActivity(),R.layout.folder_view,fls);
    this.setListAdapter(adapter); 
    

    if you want to keep it down to one call(which i dont recommend), you can do

    fill(f,null);
    

    and in the fill function check if the arraylist is null, if it is initialize it, but you must still pass it to additional calls.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone please point out what I am doing wrong in the following code?
it's assembler right? can someone please point out the progression that we've had in
Could someone please point out a site where I can find an algorithm to
What kind of data structures are these? Can someone please point out any links
Can someone please point me to the Firefox source code where Set-Cookie header is
I'm using the following function but it does work, can someone please point out
Can someone please point me to the direction where there is a example on
Can someone please point me to instructions for installing the latest Indy10 in Delphi
Can someone please share a library/code to access a USB 3G dongle in C#..?
I can't quite figure out what's going wrong. This was working earlier today and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.