Android下文件资源管理器雏形达成
发布时间:2021-11-21 19:12:51 所属栏目:PHP教程 来源:互联网
导读:学习Android,应该在掌握单个知识点之后,把多个知识点串联起来实现一些有一定代码量的小项目比较好。当然,这也是我教学中总结出来的一点经验心得,并不适合所有人。 先做需求分析(实现的功能): 1.ListView开始显示sdcard目录下的子目录和文件。 2.点击
学习Android,应该在掌握单个知识点之后,把多个知识点串联起来实现一些有一定代码量的小项目比较好。当然,这也是我教学中总结出来的一点经验心得,并不适合所有人。 先做需求分析(实现的功能): 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> 子布局也很简单,就是在水平方向上左边显示一个图标,用来显示文件夹或文件图标,右边显示文件名。 ![]() (编辑:云计算网_泰州站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |