Search code examples
androidandroid-studioandroid-fragmentsandroid-recyclerviewandroid-datepicker

how can to use Persian Calander in RecyclerViewAdapter


i using a specific date library(https://github.com/mohamad-amin/PersianMaterialDateTimePicker)

now i want using it in a button in Recycler View.

now my problem is I have to define two options in library codes :

1 - I should refer to the activity.

2 - i need to use getSupport FragmentManager().

but this page has been extends with Recycler View.Adapter and I do not know how to call these two options on this page.

RecyclerViewAdapter page :

                        PersianCalendar persianCalendar = new PersianCalendar();

                    DatePickerDialog datePickerDialog = DatePickerDialog.newInstance( StudentList.this ,
                            persianCalendar.getPersianYear() ,
                            persianCalendar.getPersianMonth() ,
                            persianCalendar.getPersianDay());




                    datePickerDialog.show( getSupportFragmentManager() , "datePickerDialog" );

In these pictures you can easily understand me :

enter image description here

enter image description here

enter image description here


Solution

  • You activity must implements TimePickerDialog.OnTimeSetListener and implement the abstact methode onTimeSet:

        public class StudentList extends AppCompatActivity implements TimePickerDialog.OnTimeSetListener {
    
    
     @Override
        public void onTimeSet(TimePickerDialog view, int hourOfDay, int minute, int second) {
    
        }
    }
    

    and inside onClick

      DatePickerDialog datePickerDialog = DatePickerDialog.newInstance((((StudentList)view.getContext()),  persianCalendar.getPersianYear(),
                            persianCalendar.getPersianMonth(),
                            persianCalendar.getPersianDay());
    

    OR :

    DatePickerDialog datePickerDialog =DatePickerDialog.newInstance(new DatePickerDialog.OnDateSetListener() {
                @Override
                public void onDateSet(DatePickerDialog view, int year, int monthOfYear, int dayOfMonth) {
    
                }
            },  persianCalendar.getPersianYear(),
                persianCalendar.getPersianMonth(),
                persianCalendar.getPersianDay());