Android的按钮启用/禁用不工作 [英] Android button enabling/disabling not working

查看:131
本文介绍了Android的按钮启用/禁用不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要禁用基于一个参数present月份的按钮。这里是我的code

I need to disable a button based on one parameter present month . Here is my code

 if(presentMonth > 20)
 {
     nextMonth.setClickable(false);
     nextMonth.setOnClickListener(null);
 }
 else
 {
    nextMonth.setOnClickListener(new MyListener());
 }  

在哪里nextMonth是按钮的名字,我试过的setEnabled,setClickable和setOnClickListener(空),但是未禁用按钮。有什么,我在这里失踪。

Where nextMonth is the Button name, I tried setEnabled , setClickable and setOnClickListener(null), but the button is not disabled. Is there anything, I am missing here.

推荐答案

我觉得方法应该工作,因为他们都是为了这一点。 的setEnabled()
是的,我已经用另外一个方式,我记得像

I think the methods should work,cause they are meant for that. setEnabled() and yes I have used one other way I remember that like

onClick(View v)
{
     if(!condition)
     {
            //perform onClick stuff
     }
}

这篇关于Android的按钮启用/禁用不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆