java - Android Switch Get Text or Transistion Not OnCheckedChanged -


I need to use the Androids switch button control, but I do not know when the user is dragging control by changing the change Need to be able to click. So if the user slips off and puts it into position so I will find out that I thought I could just onTouchListener set and then look at the list changes to the text of the state (on / off on / off) and then After speeding up your changes but I can not

  mySwitch.getText ()  

does not work for me, it returns a blank text, although I have text on text of a particular set. When the user is pulling, I should be able to detect state changes, not on click On-sight listener listener will not work for me because then only triggers when the user toggles or slides and removes the button from the finger. Any help would be appreciated. Thanks

Basic code:.

  PublicAction Extends MainActivity Activity {Private string tag = MainActivity.class.getSimpleName (); Private textview switchstats; Private Switch MySwitch; Private TextVoice MySwitch Text; Private string oldest; Private handler handler = new handler (); @Override Protected Zero OnCreate (bundled savedInstanceState) {super.onCreate (savedInstanceState); SetContentView (R.layout.activity_main); SwitchStats = (TextView) Find VVBID (RID switchStatus); MySwitch = (Switch) ViewById (R.id.mySwitch); // Switch to switch mySwitch.setChecked (false); OldState = mySwitch.getText (). ToString (); // attach a listener to check for changes in the state mySwitch.setOnCheckedChangeListener (New OnCheckedChangeListener () {@Override public void onCheckedChanged (CompoundButton buttonView, Boolean isChecked) {if (isChecked) {//switchStatus.setText("Switch Presently running ");} and {// switchStatus.setText (" switch is currently closed ");}}}); mySwitch.setOnTouchListener (New View.OnTouchListener () {@Override public boolean onTouch (see V, MotionEvent event) {// TODO Auto-generated method stub if (event.getAction () == event.ACTION_MOVE) {if (oldState. ( "off") and equals amp; & amp; mySwitch.getText () equals ( "on")). {switchStatus.setText ( "off"); oldState = "on";} if (oldState. equals ( "on") & amp; & amp; mySwitch.getText () equivalent. ( "off")) to close at {switchStatus.setText ( ""); oldState = "off";}} Log.v (TAG, "Old State:" + oldest + "My switch:" + mySwitch.getText (). ToString ()); Return Back;}}); MySwitch.setOnClickListener (New View.OnClickListener) {@Override Public Zero onClick (see v) {// TODO stub automatically created method (mySwitch.isChecked ()) {mySwitch.setChecked (wrong);}}}); Before we display the screen, (mySwitch.isChecked ()) {switchStatus.setText // Check the current status ("Switch is currently in progress"); } And {switchStatus.setText ("switch is currently closed"); }} @ Override Public Boolean On Crate Option Menu (Menu Menu) {// Increase Menu; It adds the item to the Action Bar if it exists GetMenuInflater (). Flow (R. menu activation_men, menu); Back true; }}  


Comments