-
-
Save skooltch84/b7cb5361a09b687b4b9f434ddc33d2c6 to your computer and use it in GitHub Desktop.
package com.blogspot.skooltchdev.highlightcalendar; | |
import android.content.Context; | |
import android.graphics.Color; | |
import android.support.v7.app.ActionBar; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.widget.Toast; | |
import com.github.sundeepk.compactcalendarview.CompactCalendarView; | |
import com.github.sundeepk.compactcalendarview.domain.Event; | |
import java.text.SimpleDateFormat; | |
import java.util.Date; | |
import java.util.Locale; | |
public class MainActivity extends AppCompatActivity { | |
CompactCalendarView compactCalendar; | |
private SimpleDateFormat dateFormatMonth = new SimpleDateFormat("MMMM- yyyy", Locale.getDefault()); | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
final ActionBar actionBar = getSupportActionBar(); | |
actionBar.setDisplayHomeAsUpEnabled(false); | |
actionBar.setTitle(null); | |
compactCalendar = (CompactCalendarView) findViewById(R.id.compactcalendar_view); | |
compactCalendar.setUseThreeLetterAbbreviation(true); | |
//Set an event for Teachers' Professional Day 2016 which is 21st of October | |
Event ev1 = new Event(Color.RED, 1477040400000L, "Teachers' Professional Day"); | |
compactCalendar.addEvent(ev1); | |
compactCalendar.setListener(new CompactCalendarView.CompactCalendarViewListener() { | |
@Override | |
public void onDayClick(Date dateClicked) { | |
Context context = getApplicationContext(); | |
if (dateClicked.toString().compareTo("Fri Oct 21 00:00:00 AST 2016") == 0) { | |
Toast.makeText(context, "Teachers' Professional Day", Toast.LENGTH_SHORT).show(); | |
}else { | |
Toast.makeText(context, "No Events Planned for that day", Toast.LENGTH_SHORT).show(); | |
} | |
} | |
@Override | |
public void onMonthScroll(Date firstDayOfNewMonth) { | |
actionBar.setTitle(dateFormatMonth.format(firstDayOfNewMonth)); | |
} | |
}); | |
} | |
} |
Hi, this calendar library is working fine for me. We can swipe left or right to go to other months, But I want to restrict the calendar to swipe right. I want to restrict the calendar to go to older months and the user should only be able to see the upcoming months.
Which function can I use to restrict the swipe?
Try setting a minimum date on your CalendarView in your xml resource file like android:minDate="01/01/2018"
I am able to mark dates on the calendar by fetching the data from rest api. But the dates are marked only when i touch on the calendar.
ManagementEventsListItem managementEventsListItem = new ManagementEventsListItem(); managementEventsListItem.setsEventDate(jsonObject1.getString("EVENT_START_DATE")); managementEventsListItem.setsEventDate(jsonObject1.getString("EVENT_END_DATE")); managementEventsListItem.setsID(jsonObject1.getString("ID")); mFeedList.add(managementEventsListItem); long millis = 0; try { Date date = new SimpleDateFormat("MM/dd/yyyy").parse(jsonObject1.getString("EVENT_START_DATE")); millis = date.getTime(); } catch (ParseException e) { e.printStackTrace(); } catch (NullPointerException e) { e.printStackTrace(); } Event ev1 = new Event(Color.RED, millis, jsonObject1.getString("EVENT_NAME")); compactCalendarView.addEvent(ev1);
Hi, this calendar library is working fine for me. We can swipe left or right to go to other months, But I want to restrict the calendar to swipe right. I want to restrict the calendar to go to older months and the user should only be able to see the upcoming months.
Which function can I use to restrict the swipe?