在Android上没有标准的打开和另存为对话框。在本代码中,我将详细描述一个非常简单的打开和保存对话框实现过程,对于Android初学者来说非常有用,对话框都是全屏活动的。
主要功能:
1、访问任何目录的SD卡
2、递归访问文件夹
3、单一文件选择
4、通过按硬件后退按钮升级
5、确认文件选择OK按钮
activity_open_file.xml
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:orientation="vertical" >
android:id="@+id/LvList"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
android:id="@+id/BtnOK"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="OK" />
android:id="@+id/BtnCancel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel" />
OpenFileActivity.java
package com.example.androidfiledialogs;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.Toast;
public class OpenFileActivity extends Activity
implements OnClickListener, OnItemClickListener {
ListView LvList;
ArrayList listItems = new ArrayList();
ArrayAdapter adapter;
Button BtnOK;<