How to get date from date picker in android?

前端 未结 7 1728
眼角桃花
眼角桃花 2021-01-13 10:29

I am using the DatePicker for my application. I want to get the date that I have selected (on the DatePicker), but it\'s not returning the selected

7条回答
  •  天命终不由人
    2021-01-13 11:08

    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) {
                year = selectedYear;
                month = selectedMonth;
                day = selectedDay;
    
                // set selected date into textview
                tvDisplayDate.setText(new StringBuilder().append(month + 1)
                   .append("-").append(day).append("-").append(year)
                   .append(" "));
    
                // set selected date into datepicker also
                dpResult.init(year, month, day, null);
    
            }
        };
    

    Refer Thsi link..May be this will help you.:- http://www.mkyong.com/android/android-date-picker-example/

提交回复
热议问题