【发布时间】:2011-06-18 07:15:56
【问题描述】:
请帮忙,当通过指定文件夹的完整路径单击按钮时,如何显示指定文件夹的内容。我尝试如下,但我的应用程序崩溃了。
Button buttonFom = (Button) findViewById(R.id.fom);
buttonFom.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
getDir("/mnt/sdcard/external_sd/DOC1/HW 850Xp/");
}
});
private void getDir(String dirPath) {
myPath.setText("Location: " + dirPath);
item = new ArrayList<String>();
path = new ArrayList<String>();
File f = new File(dirPath);
File[] files = f.listFiles();
if (!dirPath.equals(root)) {
item.add(root);
path.add(root);
item.add("../");
path.add(f.getParent());
}
for (int i = 0; i < files.length; i++) {
File file = files[i];
path.add(file.getPath());
if (file.isDirectory())
item.add(file.getName() + "/");
else
item.add(file.getName());
}
ArrayAdapter<String> fileList = new ArrayAdapter<String>(this,
R.layout.row, item);
setListAdapter(fileList);
}
【问题讨论】:
标签: android android-listview android-intent android-sdcard