使用 Android 日历的 setMinDate() 时出现 StackOverflowError
StackOverflowError while using Android Calendar's setMinDate()
参考上图错误
设置calendarView.setMinDate
时出现这个问题
我无法解决我在使用压延机时遇到的问题
Background concurrent copying GC freed 98234(2MB) AllocSpace objects,
1(1564KB) LOS objects, 41% free, 34MB/58MB, paused 139us total
366.099ms
这是我的代码
public class select_time extends BaseActivity {
@BindView(R.id.calendarView)
CalendarView calendarView;
DatesView datesView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.select_time);
ButterKnife.bind(this);
in = getIntent().getBooleanExtra("in", true);
datesView = new DatesView(findViewById(R.id.datesView));
datesView.setOnCalenderClick(new DatesView.onClenderClick() {
@Override
public void OnClick(boolean in) {
setWanted(in);
}
});
datesView.refresh(this);
refreshCalendar();
calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
@Override
public void onSelectedDayChange(CalendarView view, int year, int month, int day) {
Calendar calendar = Calendar.getInstance();
calendar.set(year, month, day, 0, 0, 0);
SharedPreferences prefs = getSharedPreferences("data", 0);
prefs.edit().putLong((in ? "in" : "out") + "_date", calendar.getTimeInMillis()).apply();
if (in) {
if (calendar.getTimeInMillis() == out_date.getTime() || calendar.getTimeInMillis() >= out_date.getTime()) {
calendar.add(Calendar.DATE, 1);
prefs.edit().putLong("out_date", calendar.getTimeInMillis()).apply();
}
} else {
if (calendar.getTimeInMillis() == out_date.getTime() || calendar.getTimeInMillis() <= out_date.getTime()) {
calendar.add(Calendar.DATE, -1);
prefs.edit().putLong("in_date", calendar.getTimeInMillis()).apply();
}
}
datesView.refresh(select_time.this);
}
});
}
Date in_date,out_date;
public void refreshCalendar(){
SharedPreferences prefs = getSharedPreferences("data", 0);
in_date = new Date(prefs.getLong("in_date", 0));
out_date = new Date(prefs.getLong("out_date", 0));
calendarView.setMinDate(System.currentTimeMillis() - 1000);
calendarView.setDate(in ? in_date.getTime() : out_date.getTime());
setWanted(in);
}
boolean in;
public void setWanted(boolean in) {
this.in = in;
datesView.check_in.setBackgroundColor(getResources().getColor(in ? R.color.gray : R.color.white));
datesView.check_out.setBackgroundColor(getResources().getColor(!in ? R.color.gray : R.color.white));
refreshCalendar();
}
public void clickDone(View view) {
finish();
}
}
有人可以帮助我使用 Calender 吗?
我想这是因为你在 setWanted 中调用 refreshCalendar();
,它在 calenderOnChange 中调用,然后用 datesView.refresh
再次调用,这就是你一次又一次调用它的原因,所以你需要删除这个循环。
可能是删除了 setWanted.
中的 refreshCalendar();
您正在从 refreshCalendar()
呼叫 setWanted(in);
,并且还从 setWanted(boolean in)
呼叫 refreshCalendar();
。这会创建一个无限调用循环,最终耗尽堆栈。您需要删除这两个调用之一。
参考上图错误
设置calendarView.setMinDate
时出现这个问题
我无法解决我在使用压延机时遇到的问题
Background concurrent copying GC freed 98234(2MB) AllocSpace objects, 1(1564KB) LOS objects, 41% free, 34MB/58MB, paused 139us total 366.099ms
这是我的代码
public class select_time extends BaseActivity {
@BindView(R.id.calendarView)
CalendarView calendarView;
DatesView datesView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.select_time);
ButterKnife.bind(this);
in = getIntent().getBooleanExtra("in", true);
datesView = new DatesView(findViewById(R.id.datesView));
datesView.setOnCalenderClick(new DatesView.onClenderClick() {
@Override
public void OnClick(boolean in) {
setWanted(in);
}
});
datesView.refresh(this);
refreshCalendar();
calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
@Override
public void onSelectedDayChange(CalendarView view, int year, int month, int day) {
Calendar calendar = Calendar.getInstance();
calendar.set(year, month, day, 0, 0, 0);
SharedPreferences prefs = getSharedPreferences("data", 0);
prefs.edit().putLong((in ? "in" : "out") + "_date", calendar.getTimeInMillis()).apply();
if (in) {
if (calendar.getTimeInMillis() == out_date.getTime() || calendar.getTimeInMillis() >= out_date.getTime()) {
calendar.add(Calendar.DATE, 1);
prefs.edit().putLong("out_date", calendar.getTimeInMillis()).apply();
}
} else {
if (calendar.getTimeInMillis() == out_date.getTime() || calendar.getTimeInMillis() <= out_date.getTime()) {
calendar.add(Calendar.DATE, -1);
prefs.edit().putLong("in_date", calendar.getTimeInMillis()).apply();
}
}
datesView.refresh(select_time.this);
}
});
}
Date in_date,out_date;
public void refreshCalendar(){
SharedPreferences prefs = getSharedPreferences("data", 0);
in_date = new Date(prefs.getLong("in_date", 0));
out_date = new Date(prefs.getLong("out_date", 0));
calendarView.setMinDate(System.currentTimeMillis() - 1000);
calendarView.setDate(in ? in_date.getTime() : out_date.getTime());
setWanted(in);
}
boolean in;
public void setWanted(boolean in) {
this.in = in;
datesView.check_in.setBackgroundColor(getResources().getColor(in ? R.color.gray : R.color.white));
datesView.check_out.setBackgroundColor(getResources().getColor(!in ? R.color.gray : R.color.white));
refreshCalendar();
}
public void clickDone(View view) {
finish();
}
}
有人可以帮助我使用 Calender 吗?
我想这是因为你在 setWanted 中调用 refreshCalendar();
,它在 calenderOnChange 中调用,然后用 datesView.refresh
再次调用,这就是你一次又一次调用它的原因,所以你需要删除这个循环。
可能是删除了 setWanted.
refreshCalendar();
您正在从 refreshCalendar()
呼叫 setWanted(in);
,并且还从 setWanted(boolean in)
呼叫 refreshCalendar();
。这会创建一个无限调用循环,最终耗尽堆栈。您需要删除这两个调用之一。