public class Ex04 extends ListActivity {
/** Called when the activity is first created. */
private List<String> items=null;
private List<String> paths=null;
private String rootPath="/sdcard";
private TextView mPath;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mPath=(TextView)findViewById(R.id.text1);
getFileDir(rootPath);
}
private void getFileDir(String filePath){
mPath.setText(filePath);
items=new ArrayList<String>();
paths=new ArrayList<String>();
File f=new File(filePath);
File[] ffiles=f.listFiles();
if(!filePath.equals(rootPath)){
items.add("back to"+rootPath);
paths.add(rootPath);
items.add("back to../");
paths.add(f.getParent());
}
for(int i=0;i<ffiles.length;i++) { File file=ffiles[i]; items.add(file.getName()); paths.add(file.getPath()); }
ArrayAdapter<String> fileList = new ArrayAdapter<String>(this,R.layout.file_row, items);
setListAdapter(fileList);
} protected void onListItemClick(ListView l,View v,int position,long id){
File file=new File(paths.get(position));
if(file.canRead()){
if(file.isDirectory()){
getFileDir(paths.get(position));
}
else{
new AlertDialog.Builder(this).setTitle("Message").setMessage("["+file.getName()+"] is File!").setPositiveButton("ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}).show();
}
}else{
new AlertDialog.Builder(this).setTitle("Message").setMessage("权限不足").setPositiveButton("ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}).show();
}
}
}
以下是logcat报错信息
/** Called when the activity is first created. */
private List<String> items=null;
private List<String> paths=null;
private String rootPath="/sdcard";
private TextView mPath;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mPath=(TextView)findViewById(R.id.text1);
getFileDir(rootPath);
}
private void getFileDir(String filePath){
mPath.setText(filePath);
items=new ArrayList<String>();
paths=new ArrayList<String>();
File f=new File(filePath);
File[] ffiles=f.listFiles();
if(!filePath.equals(rootPath)){
items.add("back to"+rootPath);
paths.add(rootPath);
items.add("back to../");
paths.add(f.getParent());
}
for(int i=0;i<ffiles.length;i++) { File file=ffiles[i]; items.add(file.getName()); paths.add(file.getPath()); }
ArrayAdapter<String> fileList = new ArrayAdapter<String>(this,R.layout.file_row, items);
setListAdapter(fileList);
} protected void onListItemClick(ListView l,View v,int position,long id){
File file=new File(paths.get(position));
if(file.canRead()){
if(file.isDirectory()){
getFileDir(paths.get(position));
}
else{
new AlertDialog.Builder(this).setTitle("Message").setMessage("["+file.getName()+"] is File!").setPositiveButton("ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}).show();
}
}else{
new AlertDialog.Builder(this).setTitle("Message").setMessage("权限不足").setPositiveButton("ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}).show();
}
}
}
以下是logcat报错信息
解决方案 »
- android.media.MediaScanner为何提示没找到?不能被声明!!
- 数据库rawQuery(string)方法
- 查api 丫丫丫
- android lisview 在线等
- 未来互联网发展趋势?作为软件程序员,该如何如何定位自己未来的发展方向?
- listView出现oom错误,怎么解决
- handler.obtainMessage()
- 按两次返回键结束整个程序
- 100分重谢!哪位大神能解释一下Canvas中的drawvertices方法,各种参数看不懂啊。
- 关于Android开发的一个数学功能的实现
- 急!!!android中多个Activity如何共享socket!!
- 定位位置,LocationManager中海拔(高度)获取问题
Error opening switch name path '/sys/class/switch/test'(no such fileor directory)
Error bootstrapping switch 'sys/class switch/test' (no such fileor directory)
Error opening switch name path '/sys/class/switch/test2'
unable to open stack trace file 'data/ant/traces.txt' permission denied
期待大家回复,谢谢!!!