Android custom calendar view disable specific dates

自古美人都是妖i 提交于 2019-12-02 01:41:31

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);

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

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);
        }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!