Note that there are some explanatory texts on larger screens.

plurals
  1. POVery simple ListPreference to play sound is not working. Any ideas? (tons of details)
    primarykey
    data
    text
    <p>Could someone maybe tell me what i'm doing wrong? I'm betting im missing one small thing. I've looked on the developer site and i've read some tutorials and i'm just not seeing what i did wrong.</p> <p>I'm trying to use a ListPreference to decide which sound to play on a button click.</p> <p>I have this at the top:</p> <pre><code>public String greensound; </code></pre> <p>Here's my OnClick code:</p> <pre><code>case R.id.green: SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(this); greensound = prefs.getString("greensound", "gsone"); if (greensound == "gsone") { mSoundManager.playSound(1); } else if (greensound == "gstwo") { mSoundManager.playSound(2); } else if (greensound == "gsthree") { mSoundManager.playSound(3); } break; </code></pre> <p>Here's my xml:</p> <pre><code>&lt;ListPreference android:title="Geen Button" android:key="greensound" android:summary="Select sound for the Green Button" android:entries="@array/green_list" android:entryValues="@array/green_list_values" android:defaultValue="gsone"&gt; &lt;/ListPreference&gt; //I also tried removing the default value here it didnt seem to change anything but, should it be removed? </code></pre> <p>here's my Settings.java:</p> <pre><code>package com.my.app; import android.os.Bundle; import android.preference.PreferenceActivity; public class Settings extends PreferenceActivity { @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.settings); } } </code></pre> <p>and here's my array's if that will help at all:</p> <pre><code>//This is the one I want to display to the user &lt;string-array name="green_list"&gt; &lt;item&gt;Sound One&lt;/item&gt; &lt;item&gt;Sound Two&lt;/item&gt; &lt;item&gt;Sound Three&lt;/item&gt; &lt;item&gt;Sound Four&lt;/item&gt; &lt;item&gt;Sound Five&lt;/item&gt; &lt;/string-array&gt; &lt;string-array name="green_list_values"&gt; &lt;item&gt;gsone&lt;/item&gt; &lt;item&gt;gstwo&lt;/item&gt; &lt;item&gt;gsthree&lt;/item&gt; &lt;item&gt;gsfour&lt;/item&gt; &lt;item&gt;gsfive&lt;/item&gt; &lt;/string-array&gt; </code></pre> <p>Here's a logcat that kinda looked possibly related:</p> <pre><code>08-27 01:52:07.738: WARN/Resources(6846): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f090000} 08-27 01:52:07.748: WARN/Resources(6846): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f090000} 08-27 01:52:07.758: WARN/Resources(6846): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f090000} </code></pre> <p>For those that might ask here's my DDMS > File Explorer > Data > Data > packageName > SharedPreferences This is what was in there:</p> <p>com.my.app_preferences.xml:</p> <pre><code>&lt;?xml version='1.0' encoding='utf-8' standalone='yes' ?&gt; &lt;map&gt; &lt;string name="redsound"&gt;rsone&lt;/string&gt; &lt;string name="greensound"&gt;gsone&lt;/string&gt; &lt;/map&gt; </code></pre> <p>_has_set_default_values.xml:</p> <pre><code>&lt;?xml version='1.0' encoding='utf-8' standalone='yes' ?&gt; &lt;map&gt; &lt;boolean name="_has_set_default_values" value="true" /&gt; &lt;/map&gt; </code></pre> <p>This all really confuses me more because...It looks like greensound does == gsone so.... I don't understand whats wrong its not even playing the default sound. and yes i've tested all this code without the listpreference code and they work great. I'm not sure what's wrong</p> <pre><code>mSoundManager.playSound(1); mSoundManager.playSound(2); mSoundManager.playSound(3); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload