Android开发之简单文件管理器实现方法开发之简单文件管理器实现方法
本文实例讲述了Android开发之简单文件管理器实现方法。分享给大家供大家参考,具体如下:
这里运用Java I/O、ListActivity、Dialog、Bitmap等实现简单文件管理器,可以查看目录文件,修改文件名,删除文件,打开
文件。比较简单,直接看代码:
先看布局文件:
layout/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"
>
<ListView
android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
文件列表布局:
layout/file.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp">
</TextView>
</LinearLayout>
修改文件名对话框布局文件:
layout/rename_dialog.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">
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
主Activity:
public class MainActivity extends ListActivity {
private static final String ROOT_PATH = "/";
//存储文件名称
private ArrayList<String> names = null;
//存储文件路径
private ArrayList<String> paths = null;
private View view;
private EditText editText;
/** Called when the activity is first created. */
评论0