-1
PreferenceActivity:的onResume()方法和ListPreferences的Android
public class UsersettingsActivity extends PreferenceActivity
{
public EditTextPreference nomePreferences;
public static float currValue;
public static ListPreference lista;
public static CharSequence currText;
public static String ilmionome;
public CheckBoxPreference checkboxPrefSpeech;
public CheckBoxPreference checkboxPref;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
this.overridePendingTransition(R.anim.in, R.anim.out);
/** Customizzo la actionbar */
ActionBar actionBar = getActionBar();
actionBar.setCustomView(R.layout.actionbarcustom);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowCustomEnabled(true);
nomePreferences = (EditTextPreference)getPreferenceManager().findPreference("nomepreferenze");
lista = (ListPreference)getPreferenceManager().findPreference("prefSyncFrequency");
currText = lista.getEntry();
currValue = Float.parseFloat(lista.getValue());
Toast valori = Toast.makeText(getBaseContext(), currText, Toast.LENGTH_SHORT);
valori.show();
if(currValue == 2){
currValue = MainActivity.tts.setSpeechRate(2.0f);
} else if (currValue == 1) {
currValue = MainActivity.tts.setSpeechRate(1.0f);
} else if (currValue == 0.5) {
currValue = MainActivity.tts.setSpeechRate(0.5f);
}
}
}
的arrays.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="syncFrequency">
<item name="2">Double/item>
<item name="1">Normal</item>
<item name="0">half</item>
</string-array>
<string-array name="syncFrequencyValues">
<item name="2">2</item>
<item name="1">1</item>
<item name="0">0.5</item>
</string-array>
</resources>
好吧,如果我選擇 「雙師型」 例如,我從這個活動退出回到我的MainActivity,語速仍然一樣!我需要退出應用程序,然後它的作品!所以這意味着在MainActivity
的onResume()需要一些調用PreferenceActivity
的值。現在瞭解了嗎?
編輯:
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory
android:summary="Opzioni lettura sms"
android:fontFamily="sans-serif-light"
android:title="Opzioni">
<CheckBoxPreference
android:key="firstDependent"
android:fontFamily="sans-serif-light"
android:summary="@string/autorizza"
android:title="@string/letturanotifiche"
/>
<EditTextPreference
android:title="@string/nomepreferences"
android:key="nomepreferenze"
android:fontFamily="sans-serif-light"
android:summary="@string/nomepreferencesdesc"
android:inputType="text"
android:dialogTitle="@string/nameis"
/>
<ListPreference
android:key="prefSyncFrequency"
android:entries="@array/syncFrequency"
android:summary="@string/pref_sync_frequency_summary"
android:entryValues="@array/syncFrequencyValues"
android:title="@string/pref_sync_frequency" />
</PreferenceCategory>
<!--Any other categories include here-->
</PreferenceScreen>
什麼是您的活動中的tts? –
'tts = new TextToSpeech(this,this);'它是'TextToSpeech'。我無法理解如何改變速度或偏好! –