我正在尝试使用日期选择器对话框,但是我遇到了一些方法的问题。
在这种方法中,'。set'和'。toMillis'都提出'无法解决方法:
O(n)
在这种方法中,它再次是'.set'而且我也'无法解决'。monthDay','。month'和'.year'上的符号。另外,'时间'要求构造函数,但我不知道哪一个:
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_DIALOG_ID:
final TextView dob = (TextView) findViewById(R.id.TextView_DOB_Info);
DatePickerDialog dateDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
Time dateOfBirth = new Time();
dateOfBirth.set(dayOfMonth, monthOfYear, year);
long dtDob = dateOfBirth.toMillis(true);
dob.setText(DateFormat.format("MMMM dd, yyyy", dtDob));
Editor editor = mGameSettings.edit();
editor.putLong(GAME_PREFERENCES_DOB, dtDob);
editor.commit();
}
}, 0, 0, 0);
return dateDialog;
该类的完整代码,以便您可以在上下文中看到它,如下所示:
@Override
protected void onPrepareDialog(int id, Dialog dialog) {
super.onPrepareDialog(id, dialog);
switch (id) {
case DATE_DIALOG_ID:
// Handle any DatePickerDialog initialization here
DatePickerDialog dateDialog = (DatePickerDialog) dialog;
int iDay, iMonth, iYear;
// Check for date of birth preference
if (mGameSettings.contains(GAME_PREFERENCES_DOB)) {
// Retrieve Birth date setting from preferences
long msBirthDate = mGameSettings.getLong(GAME_PREFERENCES_DOB, 0);
Time dateOfBirth = new Time();
dateOfBirth.set(msBirthDate);
iDay = dateOfBirth.monthDay;
iMonth = dateOfBirth.month;
iYear = dateOfBirth.year;
} else {
Calendar cal = Calendar.getInstance();
// Today's date fields
iDay = cal.get(Calendar.DAY_OF_MONTH);
iMonth = cal.get(Calendar.MONTH);
iYear = cal.get(Calendar.YEAR);
}
// Set the date in the DatePicker to the date of birth OR to the
// current date
dateDialog.updateDate(iYear, iMonth, iDay);
return;
case PASSWORD_DIALOG_ID:
// Handle any Password Dialog initialization here
// Since we don't want to show old password dialogs, just set new
// ones, we need not do anything here
// Because we are not "reusing" password dialogs once they have
// finished, but removing them from
// the Activity Dialog pool explicitly with removeDialog() and
// recreating them as needed.
return;
}
一如既往,任何帮助都非常感激。
由于
答案 0 :(得分:1)
您导入了错误的类:
import java.sql.Time;
导入:
import android.text.format.Time;
此类在API级别22中已弃用。使用GregorianCalendar 代替。
日历和
GregorianCalendar
类的替代方法。一个 Time类的实例表示一个时刻,用。指定 第二精度