I'm working on this new project of mine and I'm trying to add an event to a simple CompactCalendarView on a specific day, my code seems good but the event isn't showing after running the application on my phone!! here's how I added the Event:
package calendar.dev.aimlroy.cal;
import android.graphics.Color;
import android.graphics.Typeface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import com.github.sundeepk.compactcalendarview.CompactCalendarView;
import com.github.sundeepk.compactcalendarview.domain.Event;
import java.text.SimpleDateFormat;
import java.util.Date;
public class MainActivity extends AppCompatActivity {
CompactCalendarView calendar;
TextView t;
SimpleDateFormat sdf;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
calendar = (CompactCalendarView) findViewById(R.id.calendarView);
String[] d = {"","","","","","",""};
calendar.setDayColumnNames(d);
t = (TextView) findViewById(R.id.textView);
Typeface custom_font = Typeface.createFromAsset(getAssets(), "fonts/avebetwan.ttf");
sdf = new SimpleDateFormat("MMM");
t.setText(sdf.format(calendar.getFirstDayOfCurrentMonth()));
t.setTypeface(custom_font);
Date date1 = new Date(2017,7,15);
Event e = new Event(Color.RED, date1.getTime(),"text1");
calendar.addEvent(e);
calendar.setListener(new CompactCalendarView.CompactCalendarViewListener() {
@Override
public void onDayClick(Date dateClicked) {
}
@Override
public void onMonthScroll(Date firstDayOfNewMonth) {
t.setText(sdf.format(calendar.getFirstDayOfCurrentMonth()));
}
});
}
}
I figured this out! the problem was on this line:
Date date1 = new Date(2017,7,15);
The year should be 117 so it can refer to 2017 instead of 2017 which refers to 3917. so that line of code should be like this:
Date date1 = new Date(117,7,15);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.