[代码 步骤]

1. 定义所需界面 main.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    ><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="horizontal"    android:layout_width="fill_parent"    android:layout_height="wrap_content"    android:gravity="bottom"    ><Buttonandroid:id="@+id/previous"      android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text=" Back "    android:gravity="right"    /> <TextViewandroid:id="@+id/path"      android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:singleLine="true"    /></LinearLayout><ListViewandroid:id="@+id/list"      android:layout_width="fill_parent"     android:layout_height="wrap_content"     /></LinearLayout>

2. 定义一些后面用到的字符串常量

public final static String FILE_QUERY = "file_query";public final static String FILE_NAME = "name";public final static String FILE_TYPE = "type";public final static String FILE_TYPE_FILE = "file";public final static String FILE_TYPE_DIRECTORY = "directory";

3. 定义存放查询结果的数据结构

//1. 定义List<Map<String,String>> value;//2. 初始化value = new ArrayList<Map<String, String>>();

4. 定义与文件有关的变量 用于存放结果

//存放 查询目标String target="";//存放 查询目标的上级目录String parent="";

5. 定义方法 用于查询目标的子文件/目录

public String updateNext(String s){    parent = target;    target += "/" + s;        return target;    }public List<Map<String,String>> getNextList(String s){    String string = updateNext(s);        if(checkIsFile(string)){        //string 就是你所需要的文件        string = updatePrevious();    }        return list(string);    }

6. 定义方法 用于查询目标的上级目录

public String updatePrevious(){    target = parent;        File file = new File(parent);    parent = file.getParent();        return target;    }public List<Map<String,String>> getPreviousList(){    String string = updatePrevious();        return list(string);    }

7. 注册查询事件: 当单击ListView 中某项 查询子文件/子目录 并刷新结果

list.setOnItemClickListener(new OnItemClickListener(){    @Override    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,    long arg3) {    // TODO Auto-generated method stub    String s = value.get((int)arg3).get("name");        value = getNextList(s);        adapter.notifyDataSetChanged();        }            });

8. 注册查询事件: 当返回Button时候 返回上级目录 并刷新结果

previous.setOnClickListener(new OnClickListener(){public void onClick(View v) {// TODO Auto-generated method stubvalue = getPreviousList();adapter.notifyDataSetChanged();}        });

done!

更多相关文章

  1. pro.Android(安卓)Media--调用内置的照相机
  2. 自定义圆角button上下间距问题
  3. android帧动画
  4. Android(安卓)Wifi模块相关常量定义.
  5. Android(安卓)自定义ProgressBar--进度自己设置图片
  6. Android_自定义View拖拽重绘
  7. android小程序 查询电话号码信息
  8. Android应用.国际化-屏幕适配-样式与主题
  9. Android(安卓)控件之八:AutoCompleteTextView自动完成文本框

随机推荐

  1. Flash闪存颗粒和SSD知识深度解析
  2. 细数主流数据中心资产管理软件
  3. NVMe Over Fabrics架构概述
  4. 创建数据库
  5. php之数据库链式操作
  6. PHP:oop->细说命名空间/命名空间类的自动
  7. js的for和php的for
  8. 4-29数组系统函数的操作
  9. 210428 PHP 函数 返回值 参数 闭包/匿名
  10. 【PHP 面向对象】面向对象(OOP)编程之解