calendar day/month/week view in android

harikrishnan picture harikrishnan · Oct 25, 2014 · Viewed 19k times · Source

I need an android calendar view like attached photo. I already tried with this library https://github.com/alamkanak/Android-Week-View for calendar view. this one is fixed static event in calendar adding only. I could not add dynamically event in this library calendar view. can anybody suggest any custom library in android.

enter image description here

sample Android-Week-View for calendar view library code :

what I have tried in this library :

This is code , statically adding event in calendar view. when run this example, I can able to see the event at particular date in calendar view.

 @Override
 public List<WeekViewEvent> onMonthChange(int newYear, int newMonth) {

  // Populate the week view with some events.
    List<WeekViewEvent> events = new ArrayList<WeekViewEvent>();

    Calendar startTime = Calendar.getInstance();
    startTime.set(Calendar.HOUR_OF_DAY, 3);
    startTime.set(Calendar.MINUTE, 0);
    startTime.set(Calendar.MONTH, newMonth-1);
    startTime.set(Calendar.YEAR, newYear);
    Calendar endTime = (Calendar) startTime.clone();
    endTime.add(Calendar.HOUR, 1);
    endTime.set(Calendar.MONTH, newMonth-1);
    WeekViewEvent event = new    WeekViewEvent(1, getEventTitle(startTime),
    startTime, endTime);
    event.setColor(getResources().getColor(R.color.event_color_01));
    events.add(event);
      return events;
    }
    when i click this event on calendar page, its showing that event
    time and date in toast.
     @Override
    public void onEventClick(WeekViewEvent event, RectF eventRect) {
    Toast.makeText(MainActivity.this, "Clicked " 
    + event.getName(), Toast.LENGTH_SHORT).show();
    Log.v("heal", "Clicked "+ event.getName()) ;
   }

Note :

  • I need to add the same event in this calendar view dynamically.
  • I don't know how to add this event.
  • I just add one event inside onCreate(). But, that event is not showing in calendar view but, values are passing to that constructor. Can anybody help me to come out this.

Answer

Raquib-ul Alam picture Raquib-ul Alam · Nov 14, 2014

The library you are using supports dynamic event adding. Check this sample to get a better idea.