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());
}
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.
try, nextMonth.setEnabled(false)
. Normally clickable property is set in the XML layout such as android:clickable="true
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
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.