我需要将日期对象放在共享首选项编辑器中。
将其转换为什么数据类型以存储在共享首选项中?通常我们
prefEditor.putString("Idetails1", Idetails1);
为字符串和元素编写。
我怎么做?我也可以将它用于日期对象吗?
private EditText pDisplayDate;
private ImageView pPickDate;
private int pYear;
private int pMonth;
private int pDay;
/** This integer will uniquely define the dialog to be used for displaying date picker.*/
static final int DATE_DIALOG_ID = 0;
Date date;
private DatePickerDialog.OnDateSetListener pDateSetListener =
new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
pYear = year;
pMonth = monthOfYear;
pDay = dayOfMonth;
updateDisplay();
displayToast();
}
};
private void updateDisplay() {
pDisplayDate.setText(
new StringBuilder()
// Month is 0 based so add 1
.append(pMonth + 1).append("/")
.append(pDay).append("/")
.append(pYear).append(" ")
);
}
private void displayToast() {
Toast.makeText(this,
new StringBuilder()
.append("Date choosen is ")
.append(pDisplayDate.getText()),
Toast.LENGTH_SHORT).show();
}