roomorama / Caldroid

A better calendar for Android
Other
1.42k stars 532 forks source link

How to show only dates in currently displayed month #395

Open chuks opened 8 years ago

chuks commented 8 years ago

Hello, Great library. I can't figure out how to only show the days of the currently displayed month. i.e. hide prev/next month's days. In a six week configuration for the months, I don't want previous and next month's days to show (should just be a blank white space, just like in Google Calendar for Android). Thanks!

staroflead commented 8 years ago

I suggest a tweak. You shall extend caldroid adapter, then you override the style color for date which in last/ next month to be same as background or set their invisibility to GONE.

aivision369 commented 8 years ago

Hello This is a very nice library. It is solved my more then problem, but i want to display only current month days only, not next / previous month days. I know that this question i ask again but i don't know how to implement in code. means starofead says that extent adapter but i don't know how to implement it please if possible then please help me

vinayak-patil commented 7 years ago

change your customizeTextView() method from CaldroidGridAdapter.java to following

**protected void customizeTextView(int position, CellView cellView) { // Get the padding of cell so that it can be restored later int topPadding = cellView.getPaddingTop(); int leftPadding = cellView.getPaddingLeft(); int bottomPadding = cellView.getPaddingBottom(); int rightPadding = cellView.getPaddingRight();

// Get dateTime of this cell
DateTime dateTime = this.datetimeList.get(position);

cellView.resetCustomStates();
resetCustomResources(cellView);
if (dateTime.getMonth() != month) {
   // cellView.addCustomState(CellView.STATE_PREV_NEXT_MONTH);

}else {
    if (dateTime.equals(getToday())) {
        cellView.addCustomState(CellView.STATE_TODAY);
    }

    // Set color of the dates in previous / next month

    // Customize for disabled dates and date outside min/max dates
    if ((minDateTime != null && dateTime.lt(minDateTime))
            || (maxDateTime != null && dateTime.gt(maxDateTime))
            || (disableDates != null && disableDatesMap
            .containsKey(dateTime))) {

        cellView.addCustomState(CellView.STATE_DISABLED);
    }

    // Customize for selected dates
    if (selectedDates != null && selectedDatesMap.containsKey(dateTime)) {
        cellView.addCustomState(CellView.STATE_SELECTED);
    }

    cellView.refreshDrawableState();

    // Set text
    cellView.setText(String.valueOf(dateTime.getDay()));

    // Set custom color if required
    setCustomResources(dateTime, cellView, cellView);

    // Somehow after setBackgroundResource, the padding collapse.
    // This is to recover the padding
    cellView.setPadding(leftPadding, topPadding, rightPadding,
            bottomPadding);
}

}**

Dawinson commented 7 years ago

As I apply this solution, I get erroneous values ​​in cells. How to fix it? calendar

pranishres commented 6 years ago

I have tried the solution provided by @VinayakPPatil to hide dates from other month but I get the same results as @Dawinson has posted. Some of the dates of the current month also gets hidden.