daterangepicker materialdesign中如何统计选中的天数?

How count the number of days selected in the daterangepicker materialdesign?

大家好,我有一个 DatePickerRange 的 material 设计,一切正常

  CalendarConstraints.Builder constraitBuilder = new CalendarConstraints.Builder();
        constraitBuilder.setStart(mesPresente);
        constraitBuilder.setEnd(limitDate);
       // selectedPair = new Pair<>(today,);  Selecionar da por default in DateRangePicker
        //Date Range Picker
        MaterialDatePicker.Builder<Pair<Long, Long>> builder = MaterialDatePicker.Builder.dateRangePicker();
        builder.setTitleText("Seleciona a data");
        //builder.setSelection(selectedPair);
        builder.setCalendarConstraints(constraitBuilder.build()); // Delemita calendario apenas no ano atual
        final MaterialDatePicker materialDatePicker = builder.build();

        txtCalendar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                materialDatePicker.show(getActivity().getSupportFragmentManager(),"DATE_PICKER");

            }
        });



        materialDatePicker.addOnPositiveButtonClickListener(new MaterialPickerOnPositiveButtonClickListener() {
            @Override
            public void onPositiveButtonClick(Object selection) {
                txtCalendar.setText(materialDatePicker.getHeaderText())
            }
        });

现在我很想数一下选中的天数,也就是选中了多少天?

目前我不知道如何获取这些信息...感谢您现在的帮助...

改变你的OnPositiveButtonClickListener

materialDatePicker.addOnPositiveButtonClickListener(new MaterialPickerOnPositiveButtonClickListener<Pair<Long, Long>>() {
  @Override public void onPositiveButtonClick(Pair<Long,Long> selection) {
      Long startDate = selection.first;
      Long endDate = selection.second;

      //count days....

  }
});

谢谢 Gabriele Mariotti 感谢您的帮助,这非常有价值,我设法找到了解决方案,

materialDatePicker.addOnPositiveButtonClickListener(new MaterialPickerOnPositiveButtonClickListener<Pair<Long, Long>>() {
  @Override public void onPositiveButtonClick(Pair<Long,Long> selection) {
      Long startDate = selection.first;
      Long endDate = selection.second;

      //count days....
       long numDays = endDate - startDate;
       int numDay = (int) TimeUnit.MILLISECONDS.toDays(numDias);

  }
});
```