Using Multiple date picker in application

走远了吗. 提交于 2019-12-11 06:23:19

问题


I want to use more than one date picker in single application, I have google searched and i get the answer for using date picker dialogue for picking the date.
But it gets complicated for my application, where i have to write the different code for every Datepicker buttons. The code is,

 private void updateDisplay() 
 {
        Date = new StringBuilder()
                    // Month is 0 based so add 1
                    .append(mDay).append("/")
                    .append(mMonth + 1).append("/")
                    .append(mYear).append(" ");

 }
 private DatePickerDialog.OnDateSetListener mDateSetListener =
            new DatePickerDialog.OnDateSetListener() 
 {
                public void onDateSet(DatePicker view, int year, 
                                      int monthOfYear, int dayOfMonth) 
                {
                    mYear = year;
                    mMonth = monthOfYear;
                    mDay = dayOfMonth;
                    updateDisplay();
                    DisplayExpDate();
                }
 };
 @Override
 protected Dialog onCreateDialog(int id)
 {
       switch (id) 
       {
       case DATE_DIALOG_ID:
          return new DatePickerDialog(this,
                    mDateSetListener,
                    mYear, mMonth, mDay);
       }
       return null;
 }

So please help me with giving more simple solution on it.


回答1:


Use DatePicker to create own DatePickerDialog that will be able to manage buttons per your requirements based on provided parameters. Here is official tutorial how to use picker to create DatePickerDialog for Fragment. You should not have problems to reuse it for your needs



来源:https://stackoverflow.com/questions/11490540/using-multiple-date-picker-in-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!