Android: DatePicker and DatePicker Dialog

前端 未结 8 566
梦如初夏
梦如初夏 2020-12-24 09:23

I have this code here on the options menu

Dialog dialog = new Dialog(ScheduleActivity.this);
dialog.setTitle(\"Add Event\");
dialog.setContentView(R.layout.         


        
8条回答
  •  醉话见心
    2020-12-24 09:56

    Try this code it is definately work:

                final Calendar c = Calendar.getInstance();
                mYear = c.get(Calendar.YEAR);
                mMonth = c.get(Calendar.MONTH);
                mDay = c.get(Calendar.DAY_OF_MONTH);
    
                DatePickerDialog dpd = new DatePickerDialog(getActivity(),
                        new DatePickerDialog.OnDateSetListener() {
    
                            @Override
                            public void onDateSet(DatePicker view, int year,
                                    int monthOfYear, int dayOfMonth) {
    
                                birth_Date.setText(dayOfMonth + "-"
                                        + (monthOfYear + 1) + "-" + year);
                            }
                        }, mYear, mMonth, mDay);
                dpd.show();
    

提交回复
热议问题