4

This is my code time view and date view. how to I will be the select date then set the current time and disable past time..and next date will be select all time will enable how to possible these options how to write this code, anybody help, how to disable past time on time picker in android using the calendar

public  void CalenderView() {

          /* ends after 1 month from now */
            Calendar endDate = Calendar.getInstance();
            endDate.add( Calendar.DAY_OF_WEEK_IN_MONTH, 1 );

            HorizontalCalendar horizontalCalendar = new HorizontalCalendar.Builder( this, R.id.calendarView )
                    .range( Calendar.getInstance(), endDate )
                    .datesNumberOnScreen( 5 )
                    .configure()
                    .formatTopText( "EEE" )
                    .formatMiddleText( "dd" )
                    .showBottomText( false )
                    .end()
                    .build();

            horizontalCalendar.getConfig()
                    .setSizeTopText( (float) 12 )
                    .setSizeMiddleText( (float) 25 );

            horizontalCalendar.setCalendarListener( new HorizontalCalendarListener() {
                @Override
                public void onDateSelected(Calendar date, int position) {

                }
            } );
        }




   public void TimePickerView(){


            //Get the widgets reference from XMLayout
            final TextView tv = (TextView) findViewById(R.id.tv);
             tp = (TimePicker) findViewById(R.id.tp);
            Button btn = (Button) findViewById(R.id.btn);

            //Set the TextView text color
                tv.setTextColor(Color.parseColor("#b601fd"));

                btn.setOnClickListener(new View.OnClickListener() {



                @Override
                public void onClick(View v) {
                    int hourOfDay = tp.getCurrentHour(); //Get TimePicker current hour
                    int minute = tp.getCurrentMinute(); //Get TimePicker current minute

                    //Display the TimePicker current time to app interface
                    String AMPM = "AM";
                    if(hourOfDay>11)
                    {
                        //Get the current hour as AM PM 12 hour format
                        hourOfDay = hourOfDay-12;
                        AMPM = "PM";
                    }
                    tv.setText("" + hourOfDay + ":" + minute + ":" + AMPM);
                }
            });
Nm Sankar
  • 41
  • 1
  • 7

1 Answers1

-4

If you are using Android DatePicker, then you can set minimum date as today's date, so dates prior to today will not be enabled. You can use this snippet:

datePicker.setMinDate(new Date().getTime());

else if you are using DatePickerDialog:

datePickerDialog.getDatePicker().setMinDate(new Date().getTime());
Insane Developer
  • 1,014
  • 10
  • 19