Android SwitchCompat和checkbox

checkbox和SwitchCompat一样的
Android SwitchCompat和checkbox

     <androidx.appcompat.widget.SwitchCompat
           android:id="@+id/swi_photo"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_gravity="end|center_vertical"
           android:layout_marginEnd="8dp" />

Android SwitchCompat和checkbox
Android SwitchCompat和checkbox
Android SwitchCompat和checkbox

    mCheckBox.setOnCheckedChangeListener((buttonView, isChecked) -> {
            if (isChecked) {
                if (tvPrice.length() == 0) {
                    btnPrice.performClick();//模拟btnprice控件点击
                }
            } else {
                tvPrice.setText(null);
                mCheckBox.setChecked(false);
            }
        });

Android SwitchCompat和checkbox

    private void releaseRequest(String thumb) {
        int isPrivate = mCheckBox.isChecked() ? 1 : 0;//判断是否有点击
        int coin = CastUtil.parseInt(tvPrice.getText().toString().trim());//获取控件上的数据然后强转
        OkHttp.create(this).postPhoto(String.valueOf(thumb), isPrivate, coin).enqueue((call, httpRes) -> {
            ToastUtil.out(httpRes.getMsg());
            mProgressDialog.dismiss();
            if (httpRes.isSuccessful()) {
                EventBus.getDefault().post(new MyPhotoEvent(MyPhotoEvent.ACTION_THUMB));
                finish();
            }
        });
    }

Android SwitchCompat和checkbox

    private void selectPhotoPrice(View view) {//点击事件后,拉起弹窗,设置回调
        if (mPhotoPricePickerDialog == null) {//做全局变量防止重复创建对象,如果為空时才初始化对象
            mPhotoPricePickerDialog = new PhotoPricePickerDialog()
                    .setCallback(fee -> {
                        tvPrice.setText(String.valueOf(fee.getCoin()));
                        mCheckBox.setChecked(true);
                    })
                    .setOnDismissListener(dialog -> {
                        if (tvPrice.length() == 0) mCheckBox.setChecked(false);
                    });
        }
        mPhotoPricePickerDialog.show(this);
    }
上一篇:mybatis做update:动态传入要更新的字段名和字段值(mybatis 3.5.7)


下一篇:Python核心编程