setClickable(false)不起作用

本文介绍了一个关于Android开发中setClickable方法使用不当导致的问题及解决方案。指出setClickable(false)需置于setOnClickListener之后,避免内部默认设置覆盖。

问题:

设置一个控件的setClickable(false)后,发现没有效果。

解决办法:

setClickable(false)方法一定要在setOnClickListener()方法之后。

因为在setOnClickListener()方法中有这样一段代码:

 if (!isClickable()) {
            setClickable(true);
 }


下面代码一直设置的clickable都是不可点击,这样相关点击事件如何触发 mBinding.newDeviceAlertsSw.setActionCheckedChangeListener((button, isCheck, fromUser) -> { mBinding.alertMethodTitle.setVisibility(isCheck ? View.VISIBLE : View.GONE); mBinding.connectionAlertsCard.setVisibility(isCheck ? View.VISIBLE : View.GONE); if (fromUser) { mViewModel.updateNewDeviceAlerts(isCheck, mBinding.pushNotificationItem.isActionChecked() ? AlertMethod.PUSH_NOTIFICATIONS : AlertMethod.EMAIL); mBinding.newDeviceAlertsSw.getActionSwitch().setStateLoading(true); mBinding.newDeviceAlertsSw.getActionSwitch().setClickable(false); } }); mBinding.pushNotificationItem.getActionRadio().setClickable(false); mBinding.pushNotificationItem.getContent().setSingleLine(false); mBinding.emailAlertsItem.getActionRadio().setClickable(false); mBinding.emailAlertsItem.getContent().setSingleLine(false); mBinding.pushNotificationItem.setOnClickListener(v -> { if (!mBinding.pushNotificationItem.isActionChecked()) { showNewDeviceAlertsView(true, true, false); mViewModel.updateNewDeviceAlerts(true, AlertMethod.PUSH_NOTIFICATIONS); mBinding.emailAlertsItem.getActionRadio().setStateLoading(false); mBinding.emailAlertsItem.getActionRadio().setClickable(false); mBinding.pushNotificationItem.getActionRadio().setStateLoading(true); mBinding.pushNotificationItem.getActionRadio().setClickable(false); } }); mBinding.emailAlertsItem.setOnClickListener(v -> { if (!mBinding.emailAlertsItem.isActionChecked()) { showNewDeviceAlertsView(true, false, true); mViewModel.updateNewDeviceAlerts(true, AlertMethod.EMAIL); mBinding.pushNotificationItem.getActionRadio().setStateLoading(false); mBinding.pushNotificationItem.getActionRadio().setClickable(false); mBinding.emailAlertsItem.getActionRadio().setStateLoading(true); mBinding.emailAlertsItem.getActionRadio().setClickable(false); } });
最新发布
11-04
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值