介绍
这篇文章给大家介绍怎么在Android应用中添加一个文件管理功能,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。
<强>思路:强>
获取存储器接口
遍历当前目录
利用ListView显示文件文件夹
先是布局
& lt;及# 63;xml version=?.0”;编码=皍tf-8", # 63;比; http://schemas.android.com/apk/res/android" & lt; LinearLayout xmlns: android=?; android: layout_width=癿atch_parent" android: layout_height=癿atch_parent" android:取向=皏ertical"比; & lt; HorizontalScrollView android: layout_width=癿atch_parent" android: layout_height=皐rap_content" android:滚动条=皀one"比; LinearLayout & lt; android: layout_width=皐rap_content" android: layout_height=皐rap_content" android:取向=癶orizontal" android: id=癅 + id/lyPath"比; & lt; TextView android: layout_width=皐rap_content" android: layout_height=皐rap_content" android: textAppearance=? # 63; android: textAppearance" android:文本=癅string/txt_path_now"/比; & lt; TextView android: layout_width=皐rap_content" android: layout_height=皐rap_content" android: textAppearance=? # 63; android: textAppearance" android:文本=癿nt/sdcard" android: id=癅 + id/txtPath"/比; & lt;/LinearLayout> & lt;/HorizontalScrollView> & lt;视图 android: layout_width=癿atch_parent" android: layout_height=? dp" android:背景=癅android:颜色/darker_gray"/比; LinearLayout & lt; android: layout_width=癿atch_parent" android: layout_height=? dp" android: layout_weight=?“比; & lt;列表视图 android: layout_width=癿atch_parent" android: layout_height=癿atch_parent" android: id=癅 + id/folderList"/比; & lt;/LinearLayout> & lt;/LinearLayout>
用于加载文件的物品布局
list_file_style。xml
& lt;及# 63;xml version=?.0”;编码=皍tf-8", # 63;比; http://schemas.android.com/apk/res/android" & lt; LinearLayout xmlns: android=?; xmlns:工具=癶ttp://schemas.android.com/tools" android: layout_width=癿atch_parent" android: layout_height=皐rap_content" android:取向=皏ertical"比; LinearLayout & lt; android: layout_width=癿atch_parent" android: layout_height=皐rap_content" android:取向=癶orizontal" android:写入scaleY=?.9“比; & lt;复选框 android: layout_width=皐rap_content" android: layout_height=皐rap_content" android: focusable=癴alse" android: focusableInTouchMode=癴alse" android: id=癅 + id/cbSelect"/比; & lt; ImageView android: layout_width=皐rap_content" android: layout_height=皐rap_content" android: id=癅 + id/img" android: src=https://www.yisu.com/zixun/癅mipmap/其他” 工具:忽视=" ContentDescription "/><视图 android: layout_width=" 20 dp” android: layout_height=" match_parent "/> LinearLayout > LinearLayout > LinearLayout > <视图 android: layout_width=" match_parent " android: layout_height=" 1 dp " android:背景=" @android:颜色/darker_gray "/> LinearLayout >
<>强自定义类强>
为了更好的将数据绑定到视图上我选择自定义BaseAdapter类
包czhy.grey.sun.exam.bin.adapter_; 进口android.content.Context; 进口android.view.LayoutInflater; 进口android.view.View; 进口android.view.ViewGroup; 进口android.widget.BaseAdapter; 进口android.widget.CheckBox; 进口java.io.File; 进口java.text.DecimalFormat; 进口java.text.SimpleDateFormat; 进口java.util.ArrayList; 进口java.util.HashMap; 进口czhy.grey.sun.exam.R; 进口czhy.grey.sun.exam.bin.holder_.FileHolder; 公开课FileAdapter延伸BaseAdapter { 私人ArrayList怎么在Android应用中添加一个文件管理功能