I tried here, but it did not help.
My filename filter to get directories and .txt files only:
FilenameFilter filter = new FilenameFilter()
{
public boolean accept(File dir, String name)
{
if (dir.isDirectory())
{
return true;
}
else
{
return dir.getName().endsWith(".txt");
}
}
};
I also tried !dir.isFile()
Applying the filter to the list of files and directories:
CurDir = homeDir;
dir = new File(homeDir);
values = dir.list(filter);
if (values == null)
{
Toast.makeText(this, "No Files/Folders", Toast.LENGTH_LONG).show();
}
else
{
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, values);
setListAdapter(adapter);
}
Value of homeDir:
homeDir = Environment.getExternalStorageDirectory().toString();
It still shows .png and all other files.