2

i'm new to android developing and started to develop an booking app. There is a calendar view and i want to disable booked dates in that calendar. I found out that disabling feature is not there in android default calendar. so could you please help me to find a good custom calendar view that can disable specific dates. I need a resource or a library. Thank you!

Peiris
  • 115
  • 1
  • 3
  • 14
  • Try these links:http://www.androiddevelopersolutions.com/2013/05/android-calendar-sync.html https://abinashandroid.wordpress.com/2013/07/21/how-to-create-custom-calendar-in-android/ – Srijith Jun 22 '15 at 08:23

2 Answers2

3

Include CalendarPickerView in your layout XML.

<com.squareup.timessquare.CalendarPickerView
android:id="@+id/calendar_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

In the onCreate of your activity/dialog or the onCreateView of your fragment, initialize the view with a range of valid dates as well as the currently selected date.

Calendar nextYear = Calendar.getInstance();
nextYear.add(Calendar.YEAR, 1);

CalendarPickerView calendar = (CalendarPickerView) findViewById(R.id.calendar_view);
Date today = new Date();
calendar.init(today, nextYear.getTime()).withSelectedDate(today);

enter image description here

github link- https://github.com/square/android-times-square

Maveňツ
  • 1
  • 12
  • 50
  • 89
  • have you used this calendar? there is a method to highlight dates but disable dates. anything i can do for disable dates so the user can't pick up those disabled days!!! – Peiris Jun 23 '15 at 03:50
  • @user2214782 this is the way I did http://stackoverflow.com/questions/29764521/detect-listener-on-month-scrolling-in-android-times-square – Maveňツ Jun 23 '15 at 05:13
  • @maveň here you can only disable from min date to max date. I need to know how to disable array of dates. – Ashish Dwivedi Jan 12 '16 at 13:54
  • @DwivediJi explain more – Maveňツ Jan 13 '16 at 05:04
  • how can i set all sundays as deselected dates from minDate to maxDate and all holidays should be deselected pls reply but i m using https://github.com/roomorama/Caldroid – Erum Sep 19 '16 at 08:24
0
i have faced the same problem using custom calendar ,
i just overridden the function of adapter 


 @Override
    public boolean isEnabled(int position) {
         if(mySet.contains(position))
            return true;
        else
            return false;
    }


then i call the function int the adapter view 

 isEnabled(position);




befoer that tale Hashset and add the position which is displaying the calanderview 


           // mysetSize=set.size();
            //isEnabled(Integer.parseInt(gridvalue));
            Log.d(dayView.getTag()+"------1-------"+gridvalue,"-------"+position);
        } else if ((Integer.parseInt(gridvalue) < 7) && (position > 28)) {
            dayView.setTextColor(Color.WHITE);
            dayView.setClickable(false);
            dayView.setFocusable(false);
            Log.d("-------mySet------","-------"+mySet);
            Log.d(mysetSize+"-------28------"+gridvalue,"-------"+position);
            set.add(position);

        } else {
            // setting curent month's days in blue color.
            dayView.setTextColor(Color.DKGRAY);
            Log.d(dayView.getTag()+"-------current display post------","-------"+position);
            mySet.add(position);
        }
Issac Balaji
  • 1,441
  • 1
  • 13
  • 25