GFlam
GFlam

Reputation: 1109

Android dynamic list dialog

Hi i'm looking to create a list dialog that gets the items on the list from a directory I can set up a list dialog like this

final CharSequence[] items = {<dynamic list of folder contents here>};

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Pick a File");
builder.setItems(items, new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int item) {
        Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
    }
}).show();

Now lets say the directory i want to get the items from is /sdcard/folder and it contains some files

sample.txt 
sample.zip
file1.txt
file1.zip

The list dialog that would appear would have the options

sample.txt
sample.zip
file1.txt
file1.zip

and one is pressed it can just toast the name of the file selected thanks for any help or suggestions

Upvotes: 0

Views: 2611

Answers (1)

Hakem Zaied
Hakem Zaied

Reputation: 14239

Better late than never you will do something like this

File dir = new File(Environment.getExternalStorageDirectory() + "/Agenda/files");       
final String[] items = dir.list();

then pass items to the dialog as you have showed.

Upvotes: 1

Related Questions