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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
| 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.view.View; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.Toast; 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); } @Override protected void onListItemClick(ListView l, View v, int position, long id) { // TODO Auto-generated method stub File selected = new File(fileList.get(position)); if (selected.isDirectory()){ ListDir(selected); } else { Toast.makeText(AndroidListFilesActivity. this , selected.toString() + " selected" , Toast.LENGTH_LONG).show(); } } 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); } } </string></string></string></string> |
Wednesday, June 26, 2013
Navigation in files/directory
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment