You can make use of the setTag(Object o)
and getTag()
attributes for button..
By default
in xml set the tag as "on"(according to your need):
And then in JAVA:
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(b.getTag().toString().trim().equals("on"))
{
b.setTag("off");
//And your neceaasary code
}
else if(b.getTag().toString().trim().equals("off"))
{
b.setTag("on");
//And your neceaasary code
}
}
});