Cdacians

Cdacians
Cdacians

Tuesday, 7 August 2012

List files/directory in Android


List files/directory in Android

List files/directory in Android
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.AndroidListFiles;
 
import java.io.File;
import java.util.ArrayList;
import java.util.List;
 
import android.app.ListActivity;
import android.os.Bundle;
import android.os.Environment;
import android.widget.ArrayAdapter;
 
public class AndroidListFilesActivity extends ListActivity {
  
 private List<String> fileList = new ArrayList<String>();
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
         
        File root = new File(Environment
          .getExternalStorageDirectory()
          .getAbsolutePath());
        ListDir(root);
 
    }
     
    void ListDir(File f){
     File[] files = f.listFiles();
     fileList.clear();
     for (File file : files){
      fileList.add(file.getPath()); 
     }
      
     ArrayAdapter<String> directoryList
     = new ArrayAdapter<String>(this,
       android.R.layout.simple_list_item_1, fileList);
     setListAdapter(directoryList);
    }
 
}


akm
www.cdacians.com

No comments:

Post a Comment