This code is an Xamarin code.
_Display_Switch = (Switch)_TT.FindViewById(Resource.Id._Display_Switch);
_Display_Switch.Checked = _Saved_Data.GetBoolean("Test_Switch", false);
if (_Saved_Data.GetBoolean("Test_Switch", false) == true)
{
Toast.MakeText (Activity, "Enable Display", ToastLength.Short).Show();
}
else if (_Saved_Data.GetBoolean("Test_Switch", false) == false)
{
Toast.MakeText (Activity, "Disable Display", ToastLength.Short).Show();
}
_Display_Switch.CheckedChange += _Display_Switch_CheckedChange;
private void _Display_Switch_CheckedChange(object sender, CompoundButton.CheckedChangeEventArgs e)
{
if (e.IsChecked == true)
{
Toast.MakeText (Activity, "Enable Display", ToastLength.Short).Show();
}
else if (e.IsChecked == false)
{
Toast.MakeText (Activity, "Disable Display", ToastLength.Short).Show();
}
_Data_Edit.PutBoolean("Test_Switch", e.IsChecked);
_Data_Edit.Apply();
}
You have to do the event from the top one more time. Even when you turn it off and on An event appeared. Can't I use this right away without declaring the event again in the sentence above?
if (_Saved_Data.GetBoolean("Test_Switch", false) == true)
{
Toast.MakeText (Activity, "Enable Display", ToastLength.Short).Show();
}
else if (_Saved_Data.GetBoolean("Test_Switch", false) == false)
{
Toast.MakeText (Activity, "Disable Display", ToastLength.Short).Show();
}
In other words, Even if I delete this part, I want the event to occur normally when it is turned off.
sharedpreferences switch
After importing the switch
object and registering CheckedChange
, you can call the preference value and set the checked
value. In the current order, it seems that the preference value is set first in checked and the checked change is registered.
565 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
592 GDB gets version error when attempting to debug with the Presense SDK (IDE)
867 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
573 PHP ssh2_scp_send fails to send files as intended
593 Uncaught (inpromise) Error on Electron: An object could not be cloned
© 2024 OneMinuteCode. All rights reserved.