Android自定义对话框列表
2011-04-20 15:04
477 查看
学习Android,在文件操作时弹出一个对话框作为弹出菜单(习惯叫法 :-) ):
new AlertDialog.Builder(MyActivity.this)
.setTitle("标题")
.setItems(menu,listener)
.show();
其中:
menu:
String[] menu={"打开","重命名","删除","复制","剪切","自动重命名"};
listener:
OnClickListener listener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which)
{
//TODO 点击项处理
}
};
当menu内容多时,一屏显示不下,看了看间隔比较到,字体也比较大,如果修改得小一些就可以在一屏显示了。
改造对话框:
List<Map<String,String>> filemenu= new ArrayList<Map<String, String>>();
for(int i=0;i<menu.length;i++){
Map<String,String> m=new HashMap<String,String>();
m.put("id",menu[i]);
filemenu.add(m);
}
SimpleAdapter adapter = new SimpleAdapter(FileManager.this,
(List<Map<String,String>>) filemenu, R.layout.popupmenu,
new String[] { "id"}, new int[] {R.id.txtItem});
new AlertDialog.Builder(FileManager.this)
.setTitle(R.string.OptionMenuTitle)
//通过自定义适配器来显示菜单
.setAdapter(adapter,listener)
.show();
其中R.layout.popupmenu:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="TextView"
android:id="@+id/txtItem"
android:textColor="@color/blue"
android:textSize="24sp"
>
</TextView>
<ListView android:id="@id/android:list" android:drawSelectorOnTop="false" android:layout_width="wrap_content" android:layout_height="wrap_content"></ListView>
</LinearLayout>
只需要修改这个xml布局文件就可以修改弹出项的外观了。
new AlertDialog.Builder(MyActivity.this)
.setTitle("标题")
.setItems(menu,listener)
.show();
其中:
menu:
String[] menu={"打开","重命名","删除","复制","剪切","自动重命名"};
listener:
OnClickListener listener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which)
{
//TODO 点击项处理
}
};
当menu内容多时,一屏显示不下,看了看间隔比较到,字体也比较大,如果修改得小一些就可以在一屏显示了。
改造对话框:
List<Map<String,String>> filemenu= new ArrayList<Map<String, String>>();
for(int i=0;i<menu.length;i++){
Map<String,String> m=new HashMap<String,String>();
m.put("id",menu[i]);
filemenu.add(m);
}
SimpleAdapter adapter = new SimpleAdapter(FileManager.this,
(List<Map<String,String>>) filemenu, R.layout.popupmenu,
new String[] { "id"}, new int[] {R.id.txtItem});
new AlertDialog.Builder(FileManager.this)
.setTitle(R.string.OptionMenuTitle)
//通过自定义适配器来显示菜单
.setAdapter(adapter,listener)
.show();
其中R.layout.popupmenu:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="TextView"
android:id="@+id/txtItem"
android:textColor="@color/blue"
android:textSize="24sp"
>
</TextView>
<ListView android:id="@id/android:list" android:drawSelectorOnTop="false" android:layout_width="wrap_content" android:layout_height="wrap_content"></ListView>
</LinearLayout>
只需要修改这个xml布局文件就可以修改弹出项的外观了。
相关文章推荐
- Android-Dialog对话框 全解(普通对话框,单选对话框,多选对话框,列表对话框,自定义对话框,Activity对话框)
- Android简单对话框、输入对话框、单选对话框、复选对话框、列表对话框、自定义对话框、时间对话框
- Android创建自定义视图列表对话框(数据库中的数据作为数据源,使用RecyclerView作为列表)
- android中单选列表对话框-选择个人特长
- Android简明开发教程十八:自定义对话框 Transform
- Android自定义对话框,背景颜色透明
- Android流媒体开发之-直播自定义列表
- Android自定义对话框(Dialog)位置,大小
- Android 自定义AlertDialog对话框
- Android自定义对话框
- android自定义对话框样式
- Android自定义对话框(Dialog)位置,大小
- Android自定义对话框(Dialog)位置,大小
- Android中自定义的加载对话框和加载条
- android 仿QQ列表可折叠+自定义Dialog结合的DEMO
- Android 自定义弹出菜单和对话框
- Android 自定义布局对话框避免全屏的设置
- android:常用的AlertDialog对话框及自定义对话框
- android中自定义的对话框中的EditText无法弹出输入法解决方案
- (android地图开发) 高德地图自定义对话框