4

I am using the Caldroid library for my app, and I have ran into an issue.

I only want the current month's dates to show up on my calendar.

I have looked through the Caldroid documentation, but could not find anything.

I know that I can set the max date for the calendar, but I couldn't find anything for setting the max/min for each month.

Derik
  • 45
  • 6

1 Answers1

5

Hope this will help you out :)

I had the same issue and made something like that.

Create new selector in drawable for example calendar_cell_text_color.xml. In this file you put sth like this.

<!-- Caldroid days from prev and next month -->
<item android:color="@color/white" caldroid:state_date_prev_next_month="true"/>

<!-- Caldroid days from current month -->
<item android:color="@color/black" />

Now, you have to change style of CaldroidDefaultCell .

In file style.xml add follows line.

 <!-- My Caldroid theme. -->
<style name="MyCaldroid" parent="CaldroidDefault">    
     <!--If you use compact view in Caldroid -->
    <item name="styleCaldroidNormalCell">@style/CaldroidCell</item>  

    <!-- If you use square (default) view in Caldroid-->
     <item name="styleCaldroidSquareCell">@style/CaldroidCell</item>  
</style>

 <style name="CaldroidCell" parent="CaldroidDefaultCell">        
    <item name="android:textColor">@drawable/calendar_cell_text_color</item>        
</style>

Now you need to add line to use yout theme after you initizalized caldroid.

caldroidFragment = new CaldroidFragment();
caldroidFragment.setThemeResource(R.style.MyCaldroid);

Now the dates from other months will not be visible, but still you can click on them. Im working now to figure it out how to disable them.

EDIT :

If you want to disable dates

//date argument is current month visible on screen
public void disablePrevNextMonthDay(Date date){

    disableDates.setTime(date); // disableDates is a Calendar object
    disableDates.set(Calendar.DAY_OF_MONTH, 1); // 1st day of current month

    caldroidFragment.setMinDate(disableDates.getTime());
    int maxDay = disableDates.getActualMaximum(Calendar.DAY_OF_MONTH);
    disableDates.set(Calendar.DAY_OF_MONTH, maxDay);
    caldroidFragment.setMaxDate(disableDates.getTime()); //last day of current month 
}

And you call this method in onChangeMonth() method from caldroid.

If you add to selector state_date_disabled in file similar to calendar_cell_text_color.xml and set background as white just like in previous example with text color you will have invisible non clicked dates.

bogus998
  • 126
  • 2
  • 6