0
我使用AndEngine爲設置創建動態壁紙和SharedPreferences。如何在設置中根據用戶的選擇設置新牆紙?
這裏是我的XML文件,它承載了不同的設置,用戶可以選擇動態壁紙:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="Main Settings">
<ListPreference
android:title="Background Image"
android:summary="Set the background image for the wallpaper"
android:key="listPref"
android:defaultValue="1"
android:entries="@array/background"
android:entryValues="@array/background_values" />
</PreferenceCategory>
</PreferenceScreen>
我@array看起來是這樣的:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="background">
<item>Background 1</item>
<item>Background 2</item>
</string-array>
<string-array name="background_values">
<item>1</item>
<item>2</item>
</string-array>
</resources>
我的主要壁紙活動採用此檢查用戶是否選擇了新的設置:
public void onSharedPreferenceChanged(SharedPreferences pSharedPrefs, String pKey)
{
if (prefs.getString("listPref", "Background 1").equals(2))
{
Toast.makeText(this, "test", Toast.LENGTH_LONG).show();
final Scene scene = new Scene();
final AutoParallaxBackground autoParallaxBackground = new AutoParallaxBackground(
0, 0, 0, 5);
autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(2.7f,
new Sprite(0, 0, this.mAutoParallaxCustomBackground)));
scene.setBackground(autoParallaxBackground);
}
}
我的問題是...讓我們來看看說我有10個不同的背景可供選擇:背景1,背景2,背景3等等,我將不得不繼續製作如果上述方法中的其他語句能夠關注設置中的所有背景?或者我錯過了某個步驟?必須有一種更簡單的方法來確定用戶在設置中點擊了哪個背景。
我需要在XML文件中使用'background_values'嗎?
是的,我意識到我的If語句不正確,但我還沒有想出如何讓它正常工作。
你究竟想要做什麼?值「1」和「2」代表開啓還是關閉?在任何特定時間可以超過1個背景嗎? – jmcdale