java - 如何使警报对话框中的复选框左对齐?

标签 java android eclipse

可以修改警报对话框中的复选框左对齐吗?

这是activity.java文件

AlertDialog dialog; 

final CharSequence[] items = {" Easy "," Medium "," Hard "," Very Hard "};
            // arraylist to keep the selected items
            final ArrayList seletedItems=new ArrayList();

            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("Select The Difficulty Level");
            builder.setMultiChoiceItems(items, null,
                    new DialogInterface.OnMultiChoiceClickListener() {
             // indexSelected contains the index of item (of which checkbox checked)
             @Override
             public void onClick(DialogInterface dialog, int indexSelected,
                     boolean isChecked) {
                 if (isChecked) {
                     // If the user checked the item, add it to the selected items
                     // write your code when user checked the checkbox 
                     seletedItems.add(indexSelected);
                 } else if (seletedItems.contains(indexSelected)) {
                     // Else, if the item is already in the array, remove it 
                     // write your code when user Uchecked the checkbox 
                     seletedItems.remove(Integer.valueOf(indexSelected));
                 }
             }
         })
          // Set the action buttons
         .setPositiveButton("OK", new DialogInterface.OnClickListener() {
             @Override
             public void onClick(DialogInterface dialog, int id) {
                 //  Your code when user clicked on OK
                 //  You can write the code  to save the selected item here

             }
         })
         .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
             @Override
             public void onClick(DialogInterface dialog, int id) {
                //  Your code when user clicked on Cancel

             }
         });

            dialog = builder.create();//AlertDialog dialog; create like this outside onClick
            dialog.show();
    }

...................................................... ………………

/image/rTpYb.jpg">

但是...我希望复选框显示在左侧...任何人都可以帮助我。

最佳答案

您可以将自定义 View 放入警报对话框中。在该 View 中,您可以轻松地将复选框对齐到您想要的位置。有关更多信息,请阅读本教程。 http://www.pcsalt.com/android/create-alertdialog-with-custom-layout/#sthash.yN5edpAX.FKWQjxBj.dpbs

关于java - 如何使警报对话框中的复选框左对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25357689/

相关文章:

java - 如何将 Eclipse 动态 Web 项目文件夹结构与 Tomcat6 集成

java - 多线程程序的处理器数量

java - 为什么我得到一个 null 对象?

java - 无法访问应用程序中的 h2 数据库文件

android - 使用 Android 的 Parcel 编码和解码 List<List<T>>

java - 使用 Java 接口(interface)时的 Kotlin 接口(interface)实现行为

javascript - 语法xtext(eclipse建模)和react native

java - 从 jersey 1.18.1 迁移到 jersey 1.19 时出现 NoClassDefFoundError javax/ws/rs/core/Application

Java将字节数组转换为UTF-8字符串

java - 错误- TestngTestSuiteUsingXML.java :6: error: package org. testng 不存在