我正在处理我的这个新项目,并且我试图在特定日期将事件添加到简单的CompactCalendarView,我的代码似乎很好,但事件在运行后没有显示在我的手机上的应用程序!这是我如何添加事件:
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()));
}
});
}
}
答案 0 :(得分:1)
我想出来了!问题出在这一行:
Date date1 = new Date(2017,7,15);
年份应为117,因此它可以指2017年,而不是2017年,指的是3917。 所以代码行应该是这样的:
Date date1 = new Date(117,7,15);