【Android】如何实现一个简单的文件浏览器
16lz
2022-06-14
使用ListView实现了一个最简单的SD卡文件浏览器。
Manifest文件
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.loushuai.simpleplayer"> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity" android:label="@string/title_simple_palyer"> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> intent-filter> activity> application>manifest>
layout文件
activity_main.xml
<?xml version="1.0" encoding="utf-8"?><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" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.loushuai.simpleplayer.MainActivity"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" />RelativeLayout>
list_item.xlm
<?xml version="1.0" encoding="utf-8"?><TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/myView1" android:layout_width="match_parent" android:layout_height="match_parent" android:textAppearance="?android:attr/textAppearanceLarge" android:gravity="center_vertical" android:paddingLeft="5dip" android:singleLine="true">TextView>
MainActivity.java
package com.example.loushuai.simpleplayer;import android.app.ListActivity;import android.os.Bundle;import android.os.Environment;import android.util.Log;import android.view.View;import android.widget.ListView;import android.widget.SimpleAdapter;import android.widget.Toast;import java.io.File;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import java.util.Stack;public class MainActivity extends ListActivity { public static final String COLUMN_NAME_NAME = "name"; private SimpleAdapter adapter = null; private List
完整代码请移步:https://github.com/loushuai/SimpleFileViewer
更多相关文章
- android点击按钮发出声音
- android ADB PUSH 安装apk的具体步骤 及 与 ADB INSTALL 的区别
- android读取SDCard任意路径下的文件
- Android文件权限(Linux的权限)
- android 打开word pdf excle 进行预览 (工具类总结一)
- Android(安卓)Studio环境搭建
- Android(安卓)Studio报错:the minSdk version should not be decl
- Android叠加更新
- NPM 和webpack 的基础使用