有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java AlertDialog,复选框之间应该有一条线

我有一个Alertdialog和样式是复选框,我需要在彼此之间加一条线
因为我的东西太多了。 谢谢你的帮助

这是我的密码

public Button.OnClickListener IMBL = new Button.OnClickListener() {
    public void onClick(View v) {
        AfterClick = new boolean[items.length];
        for (int i = 0; i < AfterClick.length; i++) {
            AfterClick[i] = false;
        }

        AlertDialog dialog = new AlertDialog.Builder(Daycarddd.this)
                .setTitle("skill")
                .setMultiChoiceItems(items, AfterClick,
                        new DialogInterface.OnMultiChoiceClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog,
                                    int indexSelected, boolean isChecked) {
                                if (isChecked) {

                                    for (int i = 0; i < AfterClick.length; i++) {
                                        if (AfterClick[i]) {
                                        }

                                    }
                                } else if (seletedItems
                                        .contains(indexSelected)) {
                                    // Else, if the item is already in the
                                    // array, remove it
                                    seletedItems.remove(Integer
                                            .valueOf(indexSelected));
                                }
                            }
                        })
                .setPositiveButton("confirm",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog,
                                    int id) {

                                for(int j=0;j< items.length;j++){                                           
                                    if(AfterClick[j]==true){            

                                    if(resultcheck==""){resultcheck=items[j];}else
                                      resultcheck =resultcheck+","+items[j] ;
                                    }
                                  } 
                                checkbox=resultcheck;
                                resultcheck="";
                                Toast.makeText(Daycarddd.this,
                                        checkbox,
                                        Toast.LENGTH_SHORT).show();
                            }
                        })
                .setNegativeButton("cancle",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog,
                                    int id) {
                            }
                        }).create();
        dialog.show();
    }
};

共 (1) 个答案

  1. # 1 楼答案

    要绘制水平线,请使用此布局

         <View
               android:id="@+id/viewBorder"
               android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="@android:color/darker_gray"
                />
    

    //在这里展开自定义对话框

        LayoutInflater inflater = getActivity().getLayoutInflater();
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    
        final View view = inflater.inflate(R.layout.custom_dialog, null);
        final EditText edTxtAmount = (EditText) view.findViewById(R.id.edTxtOffer);
        builder.setTitle("Make Your Offer")
                .setView(view)
                .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
    
                        // Clicked 'Okay'
                    }
                })
                .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        // Clicked 'Cancel'
                    }
                });
        return builder.create();
    }
    

    //自定义布局

     <RelativeLayout   xmlns:android="http://schemas.android.com/apk/res/android"
         android:layout_width="match_parent"
         android:layout_height="wrap_content">
     <CheckBox
        android:id="@+id/mCheckbox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:text="Your Check Box with border"/>
     <View
        android:id="@+id/viewBorder"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_below="@id/mCheckbox"
        android:background="@android:color/holo_red_dark"/>     
    

    //setView(视图)将设置自定义对话框视图