I have small issue and that is I am now working with toggle button and the first toggle button is for day or night indication and second toggle button is for indication of light is on or off. Then my requirement is when it is day then second toggle button should not work and then when nite the second toggle button should work and that should indicate whether the lights are on or off. And my code is
final ToggleButton tb = (ToggleButton) findViewById(R.id.togglebutton);
tb.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
Toast.makeText(getBaseContext(),
"Button is "+tb.getText().toString(),
Toast.LENGTH_LONG).show();
if(tb.getText().toString().equals("ON"))
{
final ToggleButton tb1= (ToggleButton) findViewById(R.id.togglebutton1);
tb1.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
Toast.makeText(getBaseContext(),
"Button is "+tb1.getText().toString(),
Toast.LENGTH_LONG).show();
}});
}
else
{
Toast.makeText(screen4.this,"It is day" , Toast.LENGTH_LONG).show();
finish();
}
}
});
Can any one help me in making the second button not to work when the first button is off. Thanks in advance
This worked for me:
Code: