How to create Switch with SSwitch Control with setOnCheckedChangeListener Get link Facebook X Pinterest Email Other Apps - December 04, 2017 Step-01:Create a Switch First.. Step-02: Write Some Java Code And Set OnCheckedChangeListener for switch MainActivity.Java public class MainActivity extends AppCompatActivity { private Switch aSwitch; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); aSwitch= (Switch) findViewById(R.id.switchId); aSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if(isChecked) { Toast.makeText(getApplicationContext(),"ON", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(getApplicationContext(),"OFF", Toast.LENGTH_SHORT).show(); } } }); } } Get link Facebook X Pinterest Email Other Apps Comments
Comments
Post a Comment