Skip to content

Listeners and Callbacks

Jean Luis Urena edited this page Aug 20, 2018 · 1 revision

Listeners and Callbacks

WeekViewLoader

Essential and required otherwise an IllegalStateException will be thrown. It is used to load the events into the calendar. A List of events needs to be returned.

weekview.setWeekViewLoader(new WeekView.WeekViewLoader() {
  @NonNull
  public List<? extends WeekViewEvent> onWeekViewLoad() {
    // return a List of WeekViewEvents.
  }
});

EventClickListener

Triggered when clicking on an event. Passes in a WeekView event and a RectF of the event.

weekview.setOnEventClickListener(new WeekView.EventClickListener() {
    @Override
    public void onEventClick(WeekViewEvent event, RectF eventRect) {
      // Do something with the event
    }
});

EventLongPressListener

Triggered when long pressing on an event. Passes in a WeekView event and a RectF of the event.

weekview.setEventLongPressListener(new WeekView.EventLongPressListener() {
    @Override
    public void onEventClick(WeekViewEvent event, RectF eventRect) {
      // Do something with the event on long press
    }
});

EmptyViewClickListener

Triggered when an empty view is clicked. Passes in a DayTime object.

weekview.setEmptyViewClickListener(new WeekView.EmptyViewClickListener() {
  @Override
  public void onEmptyViewClicked(DayTime date) {
    // Do something with the view clicked
  }
});

EmptyViewLongPressListener

Triggered when an empty view is long pressed. Passes in a DayTime object.

weekview.setEmptyViewLongPressListener(new WeekView.EmptyViewLongPressListener() {
  @Override
  public void onEmptyViewLongPress(DayTime date) {
    // Do something with the view long pressed
  }
});

AddEventClickListener

Triggered when clicked to add an event. Passes in start and end DayTime objects.

weekview.setAddEventClickListener(new WeekView.AddEventClickListener() {
  @Override
  public void setAddEventClickListener(DayTime startTime, DayTime endTime) {
    // Do something with the times.
  }
});

DropListener

Triggered when dropping a view into the calendar. Passes in the dropped view and the measured day and time coordinates. DropListener must be enabled by calling enableDropListener()

weekview.enableDropListener();
weekview.setDropListener(new WeekView.DropListener() {
  @Override
  public void onDrop(View view, DayTime date) {
    // Do something with the dropped view
  }
});