package com.fog.sdexplorer;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
public class FogSDExplorerActivity extends Activity {
/** Called when the activity is first created. */
ListView list;
TextView path;
File currentParent;
File[] currentFiles;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
list=(ListView)findViewById(R.id.list);
path=(TextView)findViewById(R.id.path);
File root=new File("/mnt/sdcard");
if(root.exists())
{
currentParent=root;
currentFiles=root.listFiles();
inflateListView(currentFiles);
}
list.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
if(currentFiles[position].isFile()) return;
File[] tmp=currentFiles[position].listFiles();
if(tmp==null || tmp.length==0)
{
Toast.makeText(FogSDExplorerActivity.this, "there is not file or the file is empty", 2000).show();
}
else
{
currentParent=currentFiles[position];
currentFiles=tmp;
inflateListView(currentFiles);
}
}
});
Button parent=(Button)findViewById(R.id.parent);
parent.setOnClickListener(new OnClickListener()
{
public void onClick(View v) {
try
{
if(!currentParent.getCanonicalPath().equals("/mnt/sdcard"))
{
currentParent=currentParent.getParentFile();
currentFiles=currentParent.listFiles();
inflateListView(currentFiles);
}
}
catch(IOException e)
{
e.printStackTrace();
}
}
});
}
private void inflateListView(File[] files) {
List<Map<String,Object>> listItems=new ArrayList<Map<String,Object>>();
for(int i=0;i<files.length;i++)
{
Map<String,Object> listItem=new HashMap<String,Object>();
if(files[i].isDirectory())
{
listItem.put("icon", android.R.drawable.ic_lock_power_off);
}
else
{
listItem.put("icon", android.R.drawable.ic_lock_lock);
}
listItem.put("fileName", files[i].getName());
listItems.add(listItem);
}
SimpleAdapter simpleAdapter=new SimpleAdapter(this,listItems,R.layout.line,
new String[]{"icon","fileName"}, new int[]{R.id.icon,R.id.file_name});
list.setAdapter(simpleAdapter);
try
{
path.setText("the path is:"+currentParent.getCanonicalPath());
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
FogSDExplorer.rar (30个子文件)
FogSDExplorer
bin
classes.dex 6KB
res
drawable-ldpi
ic_launcher.png 2KB
drawable-hdpi
ic_launcher.png 4KB
drawable-mdpi
ic_launcher.png 2KB
FogSDExplorer.apk 105KB
classes
com
fog
sdexplorer
R$layout.class 422B
R$id.class 501B
R$drawable.class 433B
R$attr.class 340B
R.class 531B
FogSDExplorerActivity$2.class 1KB
FogSDExplorerActivity.class 3KB
R$string.class 427B
FogSDExplorerActivity$1.class 2KB
resources.ap_ 100KB
res
drawable-ldpi
ic_launcher.png 2KB
drawable-hdpi
ic_launcher.png 4KB
values
strings.xml 192B
drawable-mdpi
ic_launcher.png 3KB
bg.jpg 89KB
layout
main.xml 955B
line.xml 765B
assets
gen
com
fog
sdexplorer
R.java 1KB
proguard.cfg 1KB
.settings
org.eclipse.jdt.core.prefs 208B
src
com
fog
sdexplorer
FogSDExplorerActivity.java 3KB
.project 849B
.classpath 364B
project.properties 360B
AndroidManifest.xml 743B
共 30 条
- 1
资源评论
- Android痞子2012-12-11可用谢谢分享
- hnyywq2013-01-05不能用,报错了 01-05 07:03:06.098: W/dalvikvm(325): threadid=1: thread exiting with uncaught exception (group=0x4001d800) 01-05 07:03:06.118: E/AndroidRuntime(325): FATAL EXCEPTION: main 01-05 07:03:06.118: E/AndroidRuntime(325): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.fog.sd
- 爱吃鹌鹑蛋2014-12-03感谢分享,有点用
touchsnow
- 粉丝: 1542
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功