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

  • 相关阅读:
    MTK Android 源码目录分析
    MTK Android 平台语言支持状态
    开坑了啦啦啦..
    codeforces泛做..
    用介个新的blog咯..
    【UR #5】怎样跑得更快
    【UR #5】怎样提高智商
    【集训队互测2016】消失的源代码
    口胡
    [八省联考2018]劈配
  • 原文地址:https://www.cnblogs.com/GarfieldTom/p/2022325.html
Copyright © 2020-2023  润新知