Android 将 long 值传递给 class 视图
Android pass long value to class View
我正在使用库 WeekView 当应用程序启动时,我想传递给 class 从日历中查看日期以设置第一天查看。
在 Activity 中,我设置了日历,并将其传递给 class:
calendarioFooter.add(Calendar.DATE,1);
mWeekView = (WeekView) rootView.findViewById(R.id.weekView);
mWeekView.setOnEventClickListener(this);
mWeekView.setEmptyViewClickListener(this);
mWeekView.setMonthChangeListener(this);
mWeekView.setEventLongPressListener(this);
mWeekView.setDataRicevuta(calendarioFooter.getTimeInMillis());
在class视图中,设置日历:
public class WeekView extends View {
private Long data_ricevuta;
public void setDataRicevuta(Long data_ricevuta) {
this.data_ricevuta = data_ricevuta;
}
public Long get_data_ricevuta() {
return data_ricevuta;
}
private void init() {
...
mToday = Calendar.getInstance();
mToday.setTimeInMillis(data_ricevuta);
mToday.set(Calendar.HOUR_OF_DAY, 0);
mToday.set(Calendar.MINUTE, 0);
mToday.set(Calendar.SECOND, 0);
...
...
...
}
}
但是应用程序崩溃了,我遇到了这个错误:
04-24 18:43:35.546: E/AndroidRuntime(6049): android.view.InflateException: Binary XML file line #18: Error inflating class com.alamkanak.weekview.WeekView
但是,如果我手动添加一天,它会起作用。
感谢帮助
mToday = Calendar.getInstance();
mToday.add(Calendar.DATE, 1);
mToday.set(Calendar.HOUR_OF_DAY, 0);
mToday.set(Calendar.MINUTE, 0);
mToday.set(Calendar.SECOND, 0);
来自日历文档:
https://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#setTimeInMillis(long)
setTimeInMillis 需要很长时间而不是很长时间
private long data_ricevuta;
public void setDataRicevuta(long data_ricevuta) {
this.data_ricevuta = data_ricevuta;
}
public long get_data_ricevuta() {
return data_ricevuta;
}
更改电话号码
mWeekView.setDataRicevuta(calendarioFooter.getTimeInMillis());
到
mWeekView.setDataRicevuta(Calendar.getTimeInMillis());
如果可行,那么你的 calendarioFooter 是错误的时间..
我正在使用库 WeekView 当应用程序启动时,我想传递给 class 从日历中查看日期以设置第一天查看。 在 Activity 中,我设置了日历,并将其传递给 class:
calendarioFooter.add(Calendar.DATE,1);
mWeekView = (WeekView) rootView.findViewById(R.id.weekView);
mWeekView.setOnEventClickListener(this);
mWeekView.setEmptyViewClickListener(this);
mWeekView.setMonthChangeListener(this);
mWeekView.setEventLongPressListener(this);
mWeekView.setDataRicevuta(calendarioFooter.getTimeInMillis());
在class视图中,设置日历:
public class WeekView extends View {
private Long data_ricevuta;
public void setDataRicevuta(Long data_ricevuta) {
this.data_ricevuta = data_ricevuta;
}
public Long get_data_ricevuta() {
return data_ricevuta;
}
private void init() {
...
mToday = Calendar.getInstance();
mToday.setTimeInMillis(data_ricevuta);
mToday.set(Calendar.HOUR_OF_DAY, 0);
mToday.set(Calendar.MINUTE, 0);
mToday.set(Calendar.SECOND, 0);
...
...
...
}
}
但是应用程序崩溃了,我遇到了这个错误:
04-24 18:43:35.546: E/AndroidRuntime(6049): android.view.InflateException: Binary XML file line #18: Error inflating class com.alamkanak.weekview.WeekView
但是,如果我手动添加一天,它会起作用。 感谢帮助
mToday = Calendar.getInstance();
mToday.add(Calendar.DATE, 1);
mToday.set(Calendar.HOUR_OF_DAY, 0);
mToday.set(Calendar.MINUTE, 0);
mToday.set(Calendar.SECOND, 0);
来自日历文档:
https://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#setTimeInMillis(long)
setTimeInMillis 需要很长时间而不是很长时间
private long data_ricevuta;
public void setDataRicevuta(long data_ricevuta) {
this.data_ricevuta = data_ricevuta;
}
public long get_data_ricevuta() {
return data_ricevuta;
}
更改电话号码
mWeekView.setDataRicevuta(calendarioFooter.getTimeInMillis());
到
mWeekView.setDataRicevuta(Calendar.getTimeInMillis());
如果可行,那么你的 calendarioFooter 是错误的时间..