android带图片的AlertDialog和文件管理器(代码)
来源:技术人生 责任编辑:栏目编辑 发表时间:2013-07-02 01:06 点击:次
AlertDialog.java
package com.leadtone.filelists;
import java.util.ArrayList;
import java.util.HashMap;
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();
}
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);
}
@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;
switch (position) {
case 0:
intent = new Intent(AlertDialogs.this, Filelist.class);
break;
default:
Toast.makeText(AlertDialogs.this,"未设", 1).show();
break;
}
&n
Toast.makeText(AlertDialogs.this,"未设", 1).show();
break;
}
&n
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>