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

  • Home
  • SEARCH
  • 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 6559919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:23:34+00:00 2026-05-25T13:23:34+00:00

Can you check my code for anything missing? I’m trying to get use the

  • 0

Can you check my code for anything missing?

I’m trying to get use the value from a listpreference in an if statement but the if statement never responds to the value stored in the listpreference.

Here the coding I’m using:

    String stringChimeVolume = clockSettings.getString("ChimeVolume",
            "Default");


    Toast.makeText(context, "The preference is: " + stringChimeVolume,
    Toast.LENGTH_SHORT).show();

    if (stringChimeVolume == "2") {
        manager.setStreamVolume(AudioManager.STREAM_MUSIC,
                2, AudioManager.FLAG_VIBRATE);

        Toast.makeText(context, "The volume is at 2: ",
                Toast.LENGTH_SHORT).show();

    } else if (stringChimeVolume == "3") {
        Toast.makeText(context, "The volume is at 3: ",
                Toast.LENGTH_SHORT).show();

        manager.setStreamVolume(AudioManager.STREAM_MUSIC,
                7, AudioManager.FLAG_VIBRATE);
    }

    else if (stringChimeVolume == "4") {
        manager.setStreamVolume(AudioManager.STREAM_MUSIC,
                15, AudioManager.FLAG_VIBRATE);
    }

I used the first Toast statement to ensure a value was there. It has the value of 2 but the Toast in the if statement for “2” is not executing.

Here is the arrays.xml I used for the listpreference:

<string-array name="chimeVolumeLabels">
    <item>Use System Volume</item>
    <item>Emad</item>
    <item>Medium</item>
    <item>Loud</item>
</string-array>

<string-array name="chimeVolumeValues">
    <item>1</item>
    <item>2</item>
    <item>3</item>
    <item>4</item>
</string-array>

This is the settings.xml with the listpreference:

<PreferenceCategory android:title="Media:">
    <CheckBoxPreference android:key="ChimeWhenMusicIsPlaying"
        android:title="@string/ChimeWhenMusicIsPlayingTitle" android:summary="@string/ChimeWhenMusicIsPlayingSummary"
        android:defaultValue="false" />

    <ListPreference android:title="Chime Volume"
        android:key="ChimeVolume" android:summary="Select volume for the chiming sound."
        android:entries="@array/chimeVolumeLabels" android:entryValues="@array/chimeVolumeValues"
        android:defaultValue="1" />

</PreferenceCategory>

All help will be greatly appreciated.

Truly,
Emad

  • 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-25T13:23:34+00:00Added an answer on May 25, 2026 at 1:23 pm

    use .equals instead of == since == compare references not the actual value

    like

    if (stringChimeVolume.equals( "2")) instead of 
    
    
    if (stringChimeVolume== "2")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a silly question, but you can use this code to check if
With this code I can check the caret position in a textarea in firefox:
How can I check if DatabaseLink`OpenSQLConnection was successful? My code is as follows conn
i have this code in c# doc.SelectSingleNode(WhoisRecord/registrant/email).InnerText how can i check whether it is
How can I rewrite this code to check for all characters including the swedish
Can you do a better code? I need to check/uncheck all childs according to
I can get all those url's whose content/type is text/html, but If I want
I can't seem to execute any code from an AJAX call or utilize the
I've just started to get into using ViewModels. Can you guys check out this
Can check out here alt text http://51hired.com/static/problem.bmp

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.