I am having trouble working with list pref. I am trying to match a list pref value to another value with if statement
I bet that doesnt make sense so I will post code...
stripedMain:
String stripeType = "";
void drawStriped() {
final SurfaceHolder holder = getSurfaceHolder();
Canvas c = null;
try {
c = holder.lockCanvas();
if (c != null) {
if (stripeType == "vert")
{
android.util.Log.d("stripedLog", "working");
}
}
} finally {
if (c != null)
holder.unlockCanvasAndPost(c);
}
.............
settings.xml:
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory
android:key="firKey"
android:title="Wallpaper Settings" >
<ListPreference
android:defaultValue="hor"
android:entries="@array/stripe_entries"
android:entryValues="@array/stripe_values"
android:key="stripe_type"
android:title="Type" />
</PreferenceCategory>
</PreferenceScreen>
shapes.xml:
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string-array name="stripe_entries">
<item>"Horizontal"</item>
<item>"Vertical"</item>
<item>"Both"</item>
<item>"Both+CrossOver"</item>
</string-array>
<string-array name="stripe_values">
<item>"hor"</item>
<item>"vert"</item>
<item>"both"</item>
<item>"bothOver"</item>
</string-array>
</resources>
This is not working and I have no idea why....
It is not working coz yu havent fetched the default shared preferences to compare it with a string
so what you have to do is fetch it and then compare like this:
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
String stripeType = prefs.getString("stripe_type", "stripe_type")
void drawStriped() {
final SurfaceHolder holder = getSurfaceHolder();
Canvas c = null;
try {
c = holder.lockCanvas();
if (c != null) {
if (stripeType.equalsIgnoreCase("vert"))
{
android.util.Log.d("stripedLog", "working");
}
}
} finally {
if (c != null)
holder.unlockCanvasAndPost(c);
}