AlertDialog.java

package com.leadtone.filelists;
import java.util.ArrayList;
import java.util.HashMap;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.SimpleAdapter;
import android.widget.Toast;
public class AlertDialogs extends Activity {
 private Button button;
 private Intent intent;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
   button = (Button) findViewById(R.id.button);
   button.setOnClickListener(openDialog);
 }
 
   @Override
 protected void onResume() {
    openAlertDialog();
  super.onResume();
 }
 private OnClickListener openDialog=new OnClickListener(){
   @Override
   public void onClick(View v) {
    openAlertDialog();//点击执行弹出登录对话框
   }
   };
   public ListAdapter getAdapter(){
    ArrayList<HashMap<String, Object>> listItem = new ArrayList<HashMap<String, Object>>();
  
    HashMap<String, Object> map = new HashMap<String, Object>();
    map.put("ImageManager", R.drawable.donkey);
    map.put("ItemManager", "ES文件管理器");
    listItem.add(map);
    HashMap<String, Object> map1 = new HashMap<String, Object>();
    map1.put("ImageManager", R.drawable.icon);
    map1.put("ItemManager",  "图片");
    listItem.add(map1);
    HashMap<String, Object> map2 = new HashMap<String, Object>();
    map2.put("ImageManager", R.drawable.icon);
    map2.put("ItemManager", "音频");
    listItem.add(map2);
    HashMap<String, Object> map3 = new HashMap<String, Object>();
    map3.put("ImageManager", R.drawable.icon);
    map3.put("ItemManager", "文档");
    listItem.add(map3);
   
   SimpleAdapter listItemAdapter= new SimpleAdapter(this,listItem,R.layout.list_items,
     new String[]{"ImageManager","ItemManager"},
     new int[]{R.id.ImageManager,R.id.ItemManager});
   return listItemAdapter;
   }
  
   public void openAlertDialog(){
    AlertDialog  ad = new AlertDialog.Builder(AlertDialogs.this).setTitle("添加附件").setAdapter(getAdapter(), new DialogInterface.OnClickListener() {
   
    @Override
    public void onClick(DialogInterface dialog, int position) {
     onCreateAttachment(position);
    }
    private void onCreateAttachment(int position) {
     switch (position) {
     case 0:
      intent = new Intent(AlertDialogs.this, Filelist.class);
      break;
     default:
      Toast.makeText(AlertDialogs.this,"未设", 1).show();
      break;
     }
     if (intent != null) {
       try {
                startActivity(intent);
             } catch (ActivityNotFoundException e) {
                Toast.makeText(AlertDialogs.this, R.string.error, 1).show();
             }
     }
    }
   }).show();
   }
   
  }
 
Filelist.java
 
?package com.leadtone.filelists;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class Filelist extends ListActivity {
 
 private List<String> items = null;
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.directory_list);
        fillWithRoot();
    }
   
    @Override
 protected void onListItemClick(ListView l, View v, int position, long id) {
  int selectionRowID = (int) id;
  if (selectionRowID == 0) {
   fillWithRoot();
  } else {
   File file = new File(items.get(selectionRowID));
   if (file.isDirectory()){
    fill(file.listFiles());
   }else{
    openDialog("您点击的地址是",file.getPath(),"取消");
   }
  }
 }
    private void fillWithRoot() {
     fill(new File("/").listFiles());
    }
 private void fill(File[] files) {
  items = new ArrayList<String>();
  items.add(getString(R.string.to_top));
  for (File file : files){
   items.add(file.getPath());
  }
  ArrayAdapter<String> fileList = new ArrayAdapter<String>(this,
    R.layout.file_row, items);
  setListAdapter(fileList);
 }
   private void openDialog(String title, String message, String button) {
         AlertDialog.Builder builder = new AlertDialog.Builder(this);
         builder.setTitle(title);
         builder.setMessage(message);
         builder.setNegativeButton(button, null);
         builder.show();
     }
}

directory_list.xml
?<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
  <ListView
    android:id="@id/android:list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
  <TextView android:id="@id/android:empty"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/no_files"/>
</LinearLayout>
 
file_row.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView android:id="@+id/text1"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>
 
list_items.xml
?<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
 android:layout_width="fill_parent" android:layout_height="fill_parent"
 android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android">
 <RelativeLayout android:layout_width="wrap_content"
  android:layout_height="wrap_content">
  <ImageView
      android:paddingTop="12dip"
   android:layout_alignParentLeft="true"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:id="@+id/ImageManager"
    />
  <TextView
      android:layout_height="wrap_content"
   android:textSize="20dip"
   android:layout_width="fill_parent"
   android:id="@+id/ItemManager"
   android:gravity="center"
   android:layout_marginTop="20sp"
   android:layout_toRightOf="@+id/ItemManager" />
  </RelativeLayout>
</LinearLayout>