top of page

Date and Time Picker Range Library | Android App Assignment Help

Updated: Dec 26, 2021

Date pickers and Time pickers provide a simple way to select a single value from a pre-determined set and we can select the range of date picker and time picker by using date and time picker library.

Library we have use for date and time pickers


dependencies {
  implementation 'com.borax12.materialdaterangepicker:library:2.0'
}

1. Implement an OnDataSetListener and OnTimeSetListerner .

2. To Create date picker dialog using the supply factory



Implement an OnDateSetLister








  • In order to set on date picker we need to implement on date set Listener interfaces typically we have to implement in Activity or fragment we have to implement this like below


public class Select extends AppCompatActivity implements DatePickerDialog.OnDateSetListener

{

} @Override public void onDateSet(DatePickerDialog view, int year, int monthOfYear, int dayOfMonth,int yearEnd, int monthOfYearEnd, int dayOfMonthEnd) {

}



Implement on TimeSetListener




  • In order to receive the time set in the picker,we will need to implement the OnTimeSetListener interfaces. Typically this will be the Activity or Fragment that creates the Pickers.


public class Select extends AppCompatActivity implements DatePickerDialog.OnDateSetListener, TimePickerDialog.OnTimeSetListener {
}

@Override
public void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute, int hourOfDayEnd, int minuteEnd) {
    Log.e("TAG---","hourOfDay: "+hourOfDay+ "  minute:"+minute+ " hourOfDayEnd:"+hourOfDayEnd+ " minuteEnd:"+minuteEnd);
    String hourString = hourOfDay < 10 ? "0" + hourOfDay : "" + hourOfDay;
    String minuteString = minute < 10 ? "0" + minute : "" + minute;
    String hourStringend = hourOfDayEnd < 10 ? "0" + hourOfDayEnd: "" + hourOfDayEnd;
    String minuteStringend = minuteEnd < 10 ? "0" + minuteEnd : "" + minuteEnd;
    String time = "" + hourString + ":" + minuteString;
    String timeEnd = "" + hourStringend + ":" + minuteStringend;

    if(hourOfDayEnd>hourOfDay) {
        time1.setText( "Start Time " + time + " End Time " + timeEnd );
    }
    else if(hourStringend.isEmpty())
    {
        Toast.makeText( Select.this, "Enter End Time", Toast.LENGTH_SHORT ).show();
    }
    else
    {
    Toast.makeText( Select.this, "Invalid End Time", Toast.LENGTH_SHORT).show();

Commenti


bottom of page