0

When I run the app for the first time, the value of dateFormat is empty, I'm very surprised, the dateFormat should return default vale"HH:mm dd-MM-yyyy"

SharedPreferences prefs =PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
String dateFormat=dateFormat("SetDate", "HH:mm dd-MM-yyyy"); 




<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
    android:key="AppPreference"
    android:summary="@string/Preferencesummary"
    android:title="@string/Preference" >

     <ListPreference
        android:defaultValue="\n"
        android:dialogTitle="@string/DateFormat"
        android:entries="@array/Mydate"
        android:entryValues="@array/Mydate_values"
        android:key="SetDate"
        android:summary="@string/DateFormatsummary"
        android:title="@string/DateFormat"
        android:layout="@layout/mypreference_layout" 
        />   

</PreferenceScreen>


<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string-array name="Mydate">
        <item>HH:mm dd-MM-yyyy</item>
        <item>HH:mm MM-dd-yyyy</item>
        <item>yyyy-MM-dd HH:mm</item>
    </string-array>
    <string-array name="Mydate_values">
        <item>HH:mm dd-MM-yyyy</item>
        <item>HH:mm MM-dd-yyyy</item>
        <item>yyyy-MM-dd HH:mm</item>
    </string-array>

</resources>
1
  • You need to add more context. Maybe you can include you entire Java file (we need to know where you are calling SharedPrefs, etc - do you have context, etc). Commented Jun 29, 2013 at 13:48

1 Answer 1

4

Well this looks like the problem to me:

android:defaultValue="\n"

Why would you expect a default value of "HH:mm dd-MM-yyyy" when you're explicitly setting it to "\n"? I suggest you change the default value, and see if that works...

(I'm not an Android developer, so maybe I'm missing something... but that seems like the obvious approach to me.)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.