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报错信息
解决方案 »
- 求教 应用强行停止问题
- 安卓程序中怎么样把变量中的数据 显示在activity界面上?
- android开发中如何判断一个网址是否被墙?
- android连接SQLite后无法跳转到下一个页面
- 大家帮忙看看,我用service调用音乐文件然后插入自己创建的数据库,在avd上正常,可是在手机上总是意外关闭
- XXX.apk 在/data/app/下,但是在界面没有出现的原因?
- android 做游戏,用到哪些类?
- 布局问题,求教!
- android GridView刷新后 怎么让数据从第一项开始显示
- 找一个android root的详细教程,,
- 急!!!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
期待大家回复,谢谢!!!