你好,游客 登录 注册 搜索
背景:
阅读新闻

Android下文件资源管理器雏形实现

[日期:2013-04-12] 来源:Linux社区  作者:ab_ba [字体:大 中 小]

学习Android,应该在掌握单个知识点之后,把多个知识点串联起来实现一些有一定代码量的小项目比较好。当然,这也是我教学中总结出来的一点经验心得,并不适合所有人。

相关阅读:Android文件管理器的源码实现 http://www.linuxidc.com/Linux/2011-10/44521.htm
 
先做需求分析(实现的功能):
 
1.ListView开始显示sdcard目录下的子目录和文件。
 
2.点击文件,Toast显示“点击的是文件”
 
3.点击目录,进入子目录,显示子目录下的子目录和文件。
 
4.back键回退到上层目录。
 
5.异常情况处理:
 
    5.1如果sdcard没有插入,则不显示列表,且提示用户应该插入sdcard后操作
 
    5.2不允许进入sdcard的上层目录
 
下面开始实现:
 
布局有两个:
 
1.主布局:file_list.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".FileExplorerActivity" >
 <TextView
    android:id="@+id/currentTv"
    android:layout_alignParentTop="true"
    android:clickable="true"
    android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
    <ListView
        android:id="@+id/fileLv"
        android:layout_below="@id/currentTv"
        android:layout_alignParentBottom="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
       
    </ListView>
   

</RelativeLayout>

布局很简单,就是放置了一个ListView控件,这里要注意的是,ListView标签下不能再放入其他的子控件。内容是通过子布局和Adapter来显示的。
 
2.ListView中的子布局file_list_item.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >
    <ImageView
        android:id="@+id/icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />
    <TextView
        android:id="@+id/filename"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

</LinearLayout>

子布局也很简单,就是在水平方向上左边显示一个图标,用来显示文件夹或文件图标,右边显示文件名。

linux
相关资讯       Android文件理器  Android资源管理器 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款