I have a text to speech application where the user can select a language and also select a male or female voice. The problem is that for each language there are different strings used to called the male and female voice but in my preference I only have two options (male and female).
<string-array name="Language">
<item>English (US)</item>
<item>English (UK)</item>
<item>French (France)</item>
<item>Spanish (Spain)</item>
<item>Italian</item>
</string-array>
<string-array name="languageAlias">
<item>"en-US"</item>
<item>"en-GB"</item>
<item>"fr-FR"</item>
<item>"es-ES"</item>
<item>"it-IT"</item>
</string-array>
<string-array name="Voice">
<item>Male</item>
<item>Female</item>
</string-array>
<string-array name="VoiceAlias">
<item>"usenglishmale"</item>
<item>"usenglishfemale"</item>
<item>"ukenglishmale"</item>
<item>"ukenglishfemale"</item>
<item>"eurfrenchmale"</item>
<item>"eurfrenchfemale"</item>
<item>"eurspanishmale"</item>
<item>"eurspanishfemale"</item>
<item>"euritalianmale"</item>
<item>"euritalianfemale"</item>
</string-array>
I’m trying to find a way to only reference the relevant male and female voiceAlias depending on the language selected. Is it possible to do this here or do I have to write some code which changes the values of the voiceAlias array depending on the language selected?
Thanks in Advance
Ok, you can accomplish this with two
ListPreferences and anOnPreferenceChangeListenerfor each. First the XML:Let’s make a new entry in res/values/array.xml:
And now in your extention of
PreferenceActivity, we’re going to take the string values which persist in yourSharedPreferencesand from them create a completely new entry in theSharedPreferenceswhich gets its value from “VoiceAlias”.