views:

294

answers:

0

I have a listview that I would like to use to display a list of strings. The problem is the items don't show up. Can anyone tell me what I am doing wrong?

Here's my code:

import java.io.File; import java.io.FileFilter; import java.util.ArrayList;

import android.app.Activity; import android.os.Bundle; import android.os.Environment; import android.widget.ArrayAdapter; import android.widget.ListView;

public class FileBrowser extends Activity implements FileFilter { private static final File HOME = Environment.getRootDirectory();

private ArrayAdapter<String> items;
private ArrayList<File> filelist;

private File current;

private ListView list;

public void onCreate(Bundle bundle)
{
    super.onCreate(bundle);
    setContentView(R.layout.browser);

    current = HOME;

    list = (ListView)findViewById(R.id.ListView01);

    filelist = new ArrayList<File>();
    items = new ArrayAdapter<String>(this, R.layout.browser, R.id.FileList);

    browseTo(HOME);

    list.setAdapter(items);
}

private void browseTo(File dest)
{
    if (dest.isDirectory())
    {
        items.clear();
        filelist.clear();
        if (dest.listFiles(this) != null)
        {
            for (File f : dest.listFiles(this))
            {
                items.add(f.getName());
                filelist.add(f);
            }
        }
        if (dest.getParentFile() != null)
        {
            items.add("<- Back");
            filelist.add(dest.getParentFile());
        }
        current = dest;
    }
    else
    {
        //Handle File Selection
    }
}

public boolean accept(File dir)
{
    String name = dir.getName();
    if (dir.isDirectory() || name.endsWith(".mp3") || name.endsWith(".wav"))
        return true;
    return false;
}

}