android文件管理器获取图片,android带图片的AlertDialog和文件管理器(代码)

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> listItem = new ArrayList>();

HashMap map = new HashMap();

map.put("ImageManager", R.drawable.donkey);

map.put("ItemManager", "ES文件管理器");

listItem.add(map);

HashMap map1 = new HashMap();

map1.put("ImageManager", R.drawable.icon);

map1.put("ItemManager",  "图片");

listItem.add(map1);

HashMap map2 = new HashMap();

map2.put("ImageManager", R.drawable.icon);

map2.put("ItemManager", "音频");

listItem.add(map2);

HashMap map3 = new HashMap();

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 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();

items.add(getString(R.string.to_top));

for (File file : files){

items.add(file.getPath());

}

ArrayAdapter fileList = new ArrayAdapter(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"?>

android:layout_width="wrap_content"

android:layout_height="wrap_content">

android:id="@id/android:list"

android:layout_width="wrap_content"

android:layout_height="wrap_content"/>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/no_files"/>

file_row.xml

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"?>

android:layout_width="fill_parent" android:layout_height="fill_parent"

android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android">

android:layout_height="wrap_content">

android:paddingTop="12dip"

android:layout_alignParentLeft="true"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:id="@+id/ImageManager"

/>

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" />

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值