Toggle button event does not work on different devices

I am testing my application on different models, and I realized that the on / off button of the toggle button does not work. This is a list of devices:

Samsung YS5360 Samsung Galaxy Note Samsung S Plus HTC Sensation XE HTC Wildfire S Motorola RAZR
LG Optimus Black Sony Ericsson Xperia neo V

I'm not sure what I am doing wrong, as I have followed all the specifications of Android. These events work on other devices. Can I help someone?

[RE-EDIT]

This is how I implement the listener:

@Override public void onCheckedChanged(CompoundButton arg0, boolean change) { if(change){ if(text.containsKey("on")){ // do something } }else{ if(text.containsKey("off")){ // do something } } if(text.containsKey("clicked")){ // do something } // } } }; 

I check on and off status, but it doesn't seem to work on other devices.

+4
source share
2 answers

Try this code

  toggle=(ToggleButton)findViewById(R.id.tglbtn); toggle.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub if(toggle.isChecked()) { Toast.makeText(getApplicationContext(), "The state is changed to on", Toast.LENGTH_LONG).show(); } else { Toast.makeText(getApplicationContext(), "The state is changed to off", Toast.LENGTH_LONG).show(); } } }); 
+2
source

Using text to determine the state of a ToggleButton is a bad idea. Use the isChecked parameter isChecked . See the documentation.

 @Override public void onCheckedChanged (CompoundButton buttonView, boolean isChecked) { if (isChecked) { /* checked. ON */ } else { /* unchecked. OFF */ } ... } 
+6
source

All Articles