How to use DatePicker in Android Preferences
I know DatePicker isn't supported in the preferences, but I wanted to use it in my Preference开发者_开发技巧sActivity. I want the user to pick a date and that date is saved in YYYYMMDD format, and then if the user wants to edit the date, it will show the previous date that was set.
I've searched everywhere but couldn't find a good example, can someone please show me in simple steps how to perform this?
To write a date and read a date object..you have to convert it into long..as for example
//To Write a date
Date d=new Date();
SharedPreferences preferences1 = getSharedPreferences("myPreferences", 0);
SharedPreferences.Editor editor1 = preferences1.edit();
editor1.putLong("keyValue",d.getTime());
//To read a date
Long x=preferences1.getLong("keyValue", 0L);
Date d=new Date(x);
精彩评论