Android按钮启用/禁用不起作用

时间:2011-11-08 05:48:59

标签: android

我需要根据当月的一个参数禁用按钮。这是我的代码

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

其中nextMonth是Button名称,我尝试了setEnabled,setClickable和setOnClickListener(null),但是没有禁用该按钮。有什么,我在这里失踪。

2 个答案:

答案 0 :(得分:1)

尝试,nextMonth.setEnabled(false)。通常,可点击的属性在XML布局中设置,例如android:clickable="true

答案 1 :(得分:0)

我认为这些方法应该有效,因为它们是有意义的。 setEnabled() 是的,我已经使用了另一种我记得的方式

onClick(View v)
{
     if(!condition)
     {
            //perform onClick stuff
     }
}
相关问题