Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7602267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:22:08+00:00 2026-05-30T23:22:08+00:00

I am trying to get a ToggleButton working but am having a few problems.

  • 0

I am trying to get a ToggleButton working but am having a few problems.
1. Its seems to revert back to the default value when it is clicked and I navigate to another screen.
2. I tried transferring its isChecked() value to another activity using SharedPreferences and it now crashes.

    <ToggleButton
    android:id="@+id/togBTN"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/homeBtn"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="106dp"
    android:text="Voice Alerts"
    android:textOff="OFF"
    android:textOn="ON" />

The above code is in my xml file.
The code below is the onClickListener code for it.

         case R.id.togBTN:
         SharedPreferences.Editor editor = preferences.edit();
         editor.putBoolean("tgpref", tg.isChecked()); // value to store
         editor.commit();
     break;
     }  

And this code is where I try to retrieve the value

SharedPreferences preferences = getPreferences(MODE_PRIVATE);
    boolean tgpref = preferences.getBoolean("tgpref", true);  //default is true
    if (tgpref = true) //if (tgpref) may be enough, not sure
    {
      speakValue = true;
    }
    else
    {
     speakValue = false;
    }

This is what I am getting in the Logcat:

    02-21 14:49:09.587: W/dalvikvm(483): threadid=1: thread exiting with uncaught exception     (group=0x40015560)
02-21 14:49:09.597: E/AndroidRuntime(483): FATAL EXCEPTION: main
02-21 14:49:09.597: E/AndroidRuntime(483): java.lang.NullPointerException
02-21 14:49:09.597: E/AndroidRuntime(483):  at ohalleran.stephanie.Traffic.SettingsActivity.onClick(SettingsActivity.java:45)
02-21 14:49:09.597: E/AndroidRuntime(483):  at android.view.View.performClick(View.java:2485)
02-21 14:49:09.597: E/AndroidRuntime(483):  at android.widget.CompoundButton.performClick(CompoundButton.java:99)
02-21 14:49:09.597: E/AndroidRuntime(483):  at android.view.View$PerformClick.run(View.java:9080)
02-21 14:49:09.597: E/AndroidRuntime(483):  at android.os.Handler.handleCallback(Handler.java:587)
02-21 14:49:09.597: E/AndroidRuntime(483):  at android.os.Handler.dispatchMessage(Handler.java:92)
02-21 14:49:09.597: E/AndroidRuntime(483):  at android.os.Looper.loop(Looper.java:130)
02-21 14:49:09.597: E/AndroidRuntime(483):  at android.app.ActivityThread.main(ActivityThread.java:3683)
02-21 14:49:09.597: E/AndroidRuntime(483):  at java.lang.reflect.Method.invokeNative(Native Method)
02-21 14:49:09.597: E/AndroidRuntime(483):  at java.lang.reflect.Method.invoke(Method.java:507)
02-21 14:49:09.597: E/AndroidRuntime(483):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
02-21 14:49:09.597: E/AndroidRuntime(483):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
02-21 14:49:09.597: E/AndroidRuntime(483):  at dalvik.system.NativeStart.main(Native Method)

Would really appreciate some help with this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T23:22:10+00:00Added an answer on May 30, 2026 at 11:22 pm

    You should use == operator instead of =.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello everyone I been trying get php uploader working but having a lot of
I'm trying get some licensing code from AndroidPit.com working, but I get Unable to
I'm trying to get a ComboBox to match a visual design, so its ToggleButton
I am trying get date of call but it's returning value of 1.1.1970(I think
Trying to get a value from a object isn't working out. class Asset <
Trying to get an ASP application deployed; it worked for a while but then
Trying to get this example working from http://www.munna.shatkotha.com/blog/post/2008/10/26/Light-box-effect-with-WPF.aspx However, I can't seem to get
Trying to get a value out of 2d array inside of a hash and
Hi am trying get GPS using network provider and GPS provider. but am getting
I'm trying get only the Saturdays and Sundays between two dates, but I don't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.