Quelqu'un peut-être me dire ce que je fais mal? Je parie que je manque une petite chose. J'ai regardé sur le site de développeur et j'ai lu quelques tutoriels et je ne vois pas ce que j'ai fait de mal. J'essaie d'utiliser un ListPreference pour décider quel son jouer sur un clic de bouton.ListPreference très simple pour lire le son ne fonctionne pas. Des idées? (tonnes de détails)
J'ai ce en haut:
public String greensound;
Voici mon code onclick:
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;
Voici mon xml:
<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">
</ListPreference>
//I also tried removing the default value here it didnt seem to change anything but, should it be removed?
voici mon Settings.java:
et voici mon tableau si cela aidera tout:
//This is the one I want to display to the user
<string-array name="green_list">
<item>Sound One</item>
<item>Sound Two</item>
<item>Sound Three</item>
<item>Sound Four</item>
<item>Sound Five</item>
</string-array>
<string-array name="green_list_values">
<item>gsone</item>
<item>gstwo</item>
<item>gsthree</item>
<item>gsfour</item>
<item>gsfive</item>
</string-array>
Voici un logcat que peut-être un peu l'air liée:
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}
Pour ceux qui pourraient poser ici est mon DDMS> Explorateur de fichiers> Données > données> packageName> SharedPreferences Voici ce qui était là:
com.my.app_preferences.xml:
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<map>
<string name="redsound">rsone</string>
<string name="greensound">gsone</string>
</map>
_has_set_default_values.xml:
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<map>
<boolean name="_has_set_default_values" value="true" />
</map>
Tout cela me confond vraiment plus parce que ... On dirait que Greensound ne == gsone donc .... Je ne comprends pas ce qui est mal son même pas jouer la son par défaut. et oui j'ai testé tout ce code sans le code de listpreference et ils fonctionnent très bien. Je ne sais pas ce qui ne va pas
mSoundManager.playSound(1);
mSoundManager.playSound(2);
mSoundManager.playSound(3);
greensound.equals (« gsone »), il était! Merci, j'étais sur le point pour casser mon téléphone !!!!!!!!!!!!!!! edit: le site ne me laissera pas le marquer comme une réponse pour encore 3 min donc je le fais quand je le peux. – brybam