带checkBox的Dialog弹框

带checkBox的Dialog弹框

====================

java:

//一键上传弹框
private void getClearFragment() {
    View view = getLayoutInflater().inflate(R.layout.check_dialog, null);
    AlertDialog builder = new AlertDialog.Builder(getActivity()).create();
    builder.setView(view);


    CheckBox cbClearOne = view.findViewById(R.id.cb_clear_one);
    CheckBox cbClearTwo = view.findViewById(R.id.cb_clear_two);
    CheckBox cbClearThree = view.findViewById(R.id.cb_clear_three);
    CheckBox cbClearFour = view.findViewById(R.id.cb_clear_four);
    CheckBox cbClearFive = view.findViewById(R.id.cb_clear_five);
    CheckBox cbClearSix = view.findViewById(R.id.cb_clear_six);
    CheckBox cbClearSeven = view.findViewById(R.id.cb_clear_seven);
    CheckBox cbClearEight = view.findViewById(R.id.cb_clear_eight);
    CheckBox cbClearNine = view.findViewById(R.id.cb_clear_nine);
    CheckBox cbClearTen = view.findViewById(R.id.cb_clear_ten);
    Button cbHisOk = view.findViewById(R.id.cb_his_ok);
    Button cbHisCanel = view.findViewById(R.id.cb_his_canel);

    cbHisOk.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            builder.cancel();
            allinter.clear();

            if (cbClearOne.isChecked()) {
                allinter.add(4);
            }
            if (cbClearTwo.isChecked()) {
                allinter.add(5);
            }
            if (cbClearThree.isChecked()) {
                allinter.add(6);
            }
            if (cbClearFour.isChecked()) {
                allinter.add(3);
            }
            if (cbClearFive.isChecked()) {
                allinter.add(116);
            }
            if (cbClearSix.isChecked()) {
                allinter.add(2);
            }
            if (cbClearSeven.isChecked()) {
                allinter.add(7);
            }
            if (cbClearEight.isChecked()) {
                allinter.add(118);
            }
            if (cbClearNine.isChecked()) {
                allinter.add(117);
            }
            if (cbClearTen.isChecked()) {
                allinter.add(122);
            }

            zd = 0;
            if (zd < allinter.size()) {

                uart.sendbyte(getHisMuluByte(allinter.get(zd)));
            }
            zd++;
            df = 0;
            isAllUp = true;
        }

    });
    cbHisCanel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            builder.cancel();
        }
    });
    builder.show();

}

==================================

xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/lib_update_app_info_bg"
    android:orientation="vertical">

    <TextView
        android:layout_width="match_parent"
        android:gravity="center"
        android:textColor="@color/black"
        android:textSize="20sp"
        android:layout_marginTop="20dp"
        android:layout_height="wrap_content"
        android:text="清空历史数据" />

    <View
        style="@style/ViewLine"
        android:layout_marginTop="20dp" />


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_margin="10dp"
        android:orientation="horizontal">

        <CheckBox
            android:id="@+id/cb_clear_one"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="1.清除定点记录"
            android:textColor="@color/black"
            android:textSize="15sp" />

        <CheckBox
            android:id="@+id/cb_clear_two"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="2.清除日冻结电能量记录"
            android:textColor="@color/black"
            android:textSize="15sp" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:orientation="horizontal">

        <CheckBox
            android:id="@+id/cb_clear_three"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="3.清除潮流反向电能量冻结"
            android:textColor="@color/black"
            android:textSize="15sp" />

        <CheckBox
            android:id="@+id/cb_clear_four"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="4.清除极值纪录"
            android:textColor="@color/black"
            android:textSize="15sp" />

    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:orientation="horizontal">

        <CheckBox
            android:id="@+id/cb_clear_five"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="5.清除录波数据"
            android:textColor="@color/black"
            android:textSize="15sp" />

        <CheckBox
            android:id="@+id/cb_clear_six"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="6.清除遥控记录"
            android:textColor="@color/black"
            android:textSize="15sp" />


    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:orientation="horizontal">

        <CheckBox
            android:id="@+id/cb_clear_seven"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="7.清除程序日志"
            android:textColor="@color/black"
            android:textSize="15sp" />

        <CheckBox
            android:id="@+id/cb_clear_eight"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="8.清除报文记录"
            android:textColor="@color/black"
            android:textSize="15sp" />


    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="10dp"
        android:layout_marginRight="10dp"
        android:orientation="horizontal">

        <CheckBox
            android:id="@+id/cb_clear_nine"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="9.清除故障日志"
            android:textColor="@color/black"
            android:textSize="15sp" />

        <CheckBox
            android:id="@+id/cb_clear_ten"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="10.备用3"
            android:textColor="@color/black"
            android:textSize="15sp" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="10dp"
        android:layout_marginRight="10dp"
        android:orientation="horizontal">

        <Button
            android:id="@+id/cb_his_ok"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="确定"
            android:textColor="@color/black"
            android:textSize="15sp" />

        <Button
            android:id="@+id/cb_his_canel"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="10dp"
            android:layout_weight="1"
            android:text="取消"
            android:textColor="@color/black"
            android:textSize="15sp" />

    </LinearLayout>
</LinearLayout>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值