Question

I am programming a notepad android app but I am having difficulties with my Open button. How do i implement it so that when I click on it, a dialog box comes up with the .txt files saved in the folder I created on the SD card? Also, how do i load the chosen file to my current activity?

Thank You

Was it helpful?

Solution

Try the Following,

File f = new File(Environment.getExternalStorageDirectory() +"/"+ dirname);
if(f.isDirectory())
{
    ArrayList<String> files= new ArrayList<String>();
    File file = new File(Environment.getExternalStorageDirectory() +"/"+ dirname+"/");
    File fileList[] = file.listFiles();
    for(int i=0;i<fileList.length;i++)
    {
        files.add(filelist[i].getAbsolutePath());
        //here you can get all files.
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top