我有一个问题:当我按下显示在ListView
我无法打开的文件夹时。我有一个文件夹类和适配器类。这是我的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
path = Environment.getExternalStorageDirectory().getPath();
file = new File(path);
folders = new ArrayList<Folders>();
lv= (ListView) findViewById(R.id.listView1);
adapter= new MyAdapter(getApplicationContext());
lv.setAdapter(adapter);
SetList();
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int pos,
long arg3) {
String newPath= adapter.folders.get(pos).getNames()+folders.get(pos).getFiles();
file = new File(path+"/"+newPath);
String[] newdirs = file.list();
folders.clear();
for (int i = 0; i < newdirs.length; i++) {
Folders fol = new Folders(newdirs[i], newdirs[i].length()+"itemes");
adapter.folders.add(fol);
}
}
});
}
public void SetList(){
String[] dirs = file.list();
for (int i = 0; i < dirs.length; i++) {
Folders fol= new Folders(dirs[i], dirs[i].length()+" files");
adapter.folders.add(fol);