Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/187.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使警报对话框中的复选框左对齐?_Java_Android_Eclipse - Fatal编程技术网

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

Java 如何使警报对话框中的复选框左对齐?,java,android,eclipse,Java,Android,Eclipse,是否可以修改“警报”对话框中的“左对齐”复选框 这是activity.java文件 徖 http://i.stack.imgur.com/rTpYb.jpg> 但是。。。我希望复选框显示在左侧…任何人都可以帮助我。您可以在alertdialog中设置自定义视图。在该视图中,您可以轻松地将复选框对齐到所需的位置。有关更多信息,请阅读本教程 试试这种方法,希望这能帮助你解决问题 结果还是一样。复选框未向左对齐: AlertDialog dialog; final CharSequence[] i

是否可以修改“警报”对话框中的“左对齐”复选框

这是activity.java文件 徖

http://i.stack.imgur.com/rTpYb.jpg>


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

您可以在alertdialog中设置自定义视图。在该视图中,您可以轻松地将复选框对齐到所需的位置。有关更多信息,请阅读本教程

试试这种方法,希望这能帮助你解决问题


结果还是一样。复选框未向左对齐:
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();
    }
dialog = builder.create();
dialog.getWindow().setGravity(Gravity.LEFT);
dialog.show();