使用 Datapicker.update(year,month,day); 来设置日期选择器,即使日期是正确的,也会给我一个随机的日期,所以请帮忙解决问题。我在添加或编辑任务时使用相同的 Activity。
下面是我的代码:
下面是我的代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add);
databaseConnector = new DatabaseConnector(this);
title = (EditText) findViewById(R.id.TitleET);
subject = (EditText) findViewById(R.id.SubjectET);
category = (Spinner) findViewById(R.id.CategorySpinner);
datePicker = (DatePicker) findViewById(R.id.datePicker);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.Category, android.R.layout.simple_spinner_item);
category.setAdapter(adapter);
extra = getIntent().getExtras();
if(extra !=null)
{
String [] spli = extra.getString("Date").split("-");
row_id = extra.getLong("row_id");
title.setText(extra.getString("Title"));
subject.setText(extra.getString("Subject"));
if(extra.getString("Category").equals("Exam"))
{
category.setSelection(0);
}
else
{
category.setSelection(1);
}
datePicker.updateDate(Integer.parseInt(spli[2]),Integer.parseInt(spli[1]),Integer.parseInt(spli[0]));
}
}