Example on ToggleButton

后端 未结 7 1384
悲哀的现实
悲哀的现实 2021-01-12 07:08

I am developing an application using a toggle button, I entered 1 or 0 in EditText. When button is clicked, the toggle button has to change if I enter 1 the tog

7条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-12 07:17

    Try this Toggle Buttons

    test_activity.xml

    
    

    Test.java

    public class Test extends Activity {
    
    private ToggleButton togglebutton;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        togglebutton = (ToggleButton) findViewById(R.id.togglebutton);
    }
    
    public void toggleclick(View v){
        if(togglebutton.isChecked())
            Toast.makeText(TestActivity.this, "ON", Toast.LENGTH_SHORT).show();
        else
            Toast.makeText(TestActivity.this, "OFF", Toast.LENGTH_SHORT).show();
        }
    }
    

提交回复
热议问题