Search code examples
androideventstogglebuttonandroid-event

toggle button event not working on various devices


I am testing my application on various models and I have realized that the toggle button ON and OFF event is not working. This is the 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 am not sure what I am doing wrong as I have followed all Android specifications. These events work on other devices. May I have some help please,anyone?

[RE-EDIT]

This is how I am implementing 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 for both ON and OFF states but this seems not to be working on other devices.


Solution

  • 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();
                 }
                 }
                 });