Android将长值传递给类View

时间:2015-04-24 17:44:55

标签: android class view calendar long-integer

我正在使用库WeekView当应用程序启动时,我想传递给类查看日历中的日期以设置第一天的视图。 在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());

在班级视图中,设置日历:

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);

1 个答案:

答案 0 :(得分:0)

来自日历文档:

https://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#setTimeInMillis(long)

setTimeInMillis需要很长时间

mWeekView.setDataRicevuta(calendarioFooter.getTimeInMillis());

改变你的电话

mWeekView.setDataRicevuta(Calendar.getTimeInMillis());

{{1}}

如果有效,那么你的calendarioFooter应该是错误的时间..