我有一个日期选择器,我想交换设置和取消按钮。
当我尝试时,两个按钮都只能用于设置。
如何避免这种情况和互换按钮。
这是我的代码。
@Override
protected Dialog onCreateDialog(int id) {
Calendar c = Calendar.getInstance();
int cyear = c.get(Calendar.YEAR);
int cmonth = c.get(Calendar.MONTH);
int cday = c.get(Calendar.DAY_OF_MONTH);
switch (id) {
case DATE_DIALOG_ID:
final DatePickerDialog datePicker = new DatePickerDialog(this,
mDateSetListener, cyear, cmonth, cday);
datePicker.setButton(DatePickerDialog.BUTTON_NEGATIVE,
this.getString(R.string.set), datePicker);
datePicker.setButton(DatePickerDialog.BUTTON_POSITIVE,
this.getString(R.string.cancel), datePicker);
return datePicker;
}
return null;
}
private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
selectedDay = Integer.parseInt(String.valueOf(dayOfMonth));
selectedMonth = Integer.parseInt(String.valueOf(monthOfYear + 1));
selectedYear = Integer.parseInt(String.valueOf(year));
String date_selected = String.valueOf(monthOfYear + 1) + " /"
+ String.valueOf(dayOfMonth) + " /" + String.valueOf(year);
textView.setText(date_selected);
}
};
提前致谢...!