每次我的代码启动回调时,都会选择日期(并在数据库中插入两次)。
当然,我不需要这种行为。注意错误是在Bluestack Emulator(android 4.3)中,Galaxy Ace以Cyanogenmod 4.4为根,但不在我的三星s3(android 4.3)中
谢谢
private void setFab(){
// BUTTON
FloatingActionButton newEventButton = (FloatingActionButton) v.findViewById(R.id.set_new_event);
newEventButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Calendar c = Calendar.getInstance();
int mYear = c.get(Calendar.YEAR);
int mMonth = c.get(Calendar.MONTH);
int mDay = c.get(Calendar.DAY_OF_MONTH);
DatePickerDialog dialog = new DatePickerDialog(getActivity(), datePickerListener, mYear, mMonth, mDay);
/*dialog.setButton(DatePickerDialog.BUTTON_POSITIVE, "OK", dialog);
dialog.setButton(DialogInterface.BUTTON_POSITIVE,"OK",dialog.onDateChanged(DatePicker view););*/
dialog.show();
}
});
}
private DatePickerDialog.OnDateSetListener datePickerListener
= new DatePickerDialog.OnDateSetListener() {
// when dialog box is closed, below method will be called.
public void onDateSet(DatePicker view, int selectedYear,
int selectedMonth, int selectedDay) {
String stringYear = Integer.toString(selectedYear);
selectedMonth = selectedMonth+1;
String stringMonth = Integer.toString(selectedMonth);
if (stringMonth.length()==1){
stringMonth = "0"+stringMonth;
}
String stringDay = Integer.toString(selectedDay);
if (stringDay.length()==1){
stringDay = "0"+stringDay;
}
String date = stringYear+"-"+stringMonth+"-"+stringDay+" 00:00:00";
setEvent(date);
//last_event = getLastEvent();
setDashboard();
}
};