0

I made an android app in which I am taking the date of birth of the user and storing them as three integers in SharedPreferences key-value pairs.

The date is picked by using inline datepicker.

I want the date selected to be same when user again opens it instead of showing today's date.

How do I use the Sharedpreferences key-value pair data and show that in the inline date instead of today's date?

Carrie Kendall
  • 11,124
  • 5
  • 61
  • 81
8A52
  • 793
  • 3
  • 12
  • 23
  • possible duplication of http://stackoverflow.com/questions/3624280/how-to-use-sharedpreferences-in-android-to-store-fetch-and-edit-values – Vivart May 13 '11 at 11:36

2 Answers2

1

Hi I found the answer on how to set the inline datepicker here is the code

OnDateChangedListener listener = new OnDateChangedListener() {

        @Override
        public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            mYear = year;
            mMonth = monthOfYear;
            mDay = dayOfMonth;
        }
    };
    date.init(prefs.getInt("year",1920),prefs.getInt("month",0),prefs.getInt("day",1),listener);

The mistake I did was not using a listener which led to force closing of the app

8A52
  • 793
  • 3
  • 12
  • 23
0

Look here for clues ... http://developer.android.com/resources/tutorials/views/hello-datepicker.html

I would think you could replace the Calendar.YEAR[.MONTH|.DAY_OF_MONTH] with your call to app preferences:

final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
Bill Mote
  • 12,644
  • 7
  • 58
  • 82
  • I think i got a solution but it is force closing the app there is method called init(int year,int month,int day,listener) for my datepicker with name date I am writing the code date.init(year,month,day,null) I am using null as I dont have listener butapp is force closing due to that. Where am i wrong – 8A52 May 13 '11 at 13:07