zoukankan      html  css  js  c++  java
  • Android自定义对话框列表

    学习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布局文件就可以修改弹出项的外观了。 

  • 相关阅读:
    密码由6-12位数字或字母组成,密码哈希加密
    获得一个字符串的汉语拼音码
    WPF中ComboBox绑定数据库自动读取产生数据
    SQL存储过程生成顺序编码
    SQL 语句调用这个存储过程,生成顺序编码
    restful(1):序列化
    Django的CBV和FBV
    权限管理组件:rbac
    ModelForm组件和forms组件补充
    BBS+Blog项目代码
  • 原文地址:https://www.cnblogs.com/GarfieldTom/p/2022325.html
Copyright © 2011-2022 走看看