package com.jone.SDCard;
import java.io.File;
import java.io.IOException;
import android.content.Context;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
public class SdcardFileAdapter extends BaseAdapter {
Context context;
File current;
File[] files;
public SdcardFileAdapter(Context context,File current) {
// TODO Auto-generated constructor stub
this.context = context;
this.current = current;
setData(current);
}
public File getCurrentParent(){
return current;
}
public void setData(File current){
files = current.listFiles();
this.current = current;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return files.length;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return files[position];
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View view;
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
TextView fileName;
ImageView fileIcon;
LinearLayout clickView;
if(convertView == null){
view = inflater.inflate(R.layout.list_item, null);
}else {
view = convertView;
}
fileIcon = (ImageView) view.findViewById(R.id.icon);
fileName = (TextView) view.findViewById(R.id.file_name);
clickView = (LinearLayout) view.findViewById(R.id.itemView);
File file = (File) getItem(position);
if(file.isDirectory()){
fileIcon.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.folder));
}else {
fileIcon.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.file));
}
fileName.setText(file.getName());
try {
((MainActivity)context).titleFilePath.setText("当前路径为:"+current.getCanonicalPath());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
clickView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(files[position].isFile()){
Toast.makeText(context,files[position].getName(), 2000).show();
}else {
current = files[position];
files = files[position].listFiles();
notifyDataSetChanged();
}
try {
((MainActivity)context).titleFilePath.setText("当前路径为:"+current.getCanonicalPath());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
return view;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
SDCardFileExplorer【文件浏览器】.zip (28个子文件)
SDCardFileExplorer【文件浏览器】
.project 854B
src
com
jone
SDCard
SdcardFileAdapter.java 3KB
MainActivity.java 2KB
AndroidManifest.xml 682B
res
drawable-ldpi
icon.png 2KB
drawable-hdpi
icon.png 4KB
drawable-mdpi
icon.png 3KB
back_48.png 4KB
file.png 23KB
folder.png 4KB
layout
list_item.xml 901B
main.xml 1KB
values
strings.xml 181B
assets
gen
com
jone
SDCard
R.java 1KB
default.properties 364B
.classpath 280B
bin
resources.ap_ 18KB
com
jone
SDCard
R$layout.class 418B
SdcardFileAdapter$1.class 2KB
R$drawable.class 480B
R$attr.class 331B
SdcardFileAdapter.class 3KB
R$id.class 532B
R.class 510B
R$string.class 418B
MainActivity.class 3KB
SDCardFileExplorer.apk 24KB
classes.dex 7KB
共 28 条
- 1
yaya_soft
- 粉丝: 124
- 资源: 29
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页