@BindView(R.id.datesList)
ListView datesList;
final ArrayList<DateTime> dates = new ArrayList<>();
в MainActivity.onCreate
addDatesRange(DateTime.now());
final DatesAdapter adapter = new DatesAdapter(this, R.layout.date_item, dates);
datesList.setAdapter(adapter);
datesList.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
String msg = String.format("onScroll: firstVisibleItem = %d, visibleItemCount = %d, totalItemCount = %d", firstVisibleItem, visibleItemCount, totalItemCount);
System.out.println(msg);
if (totalItemCount > 5 && firstVisibleItem < 5) {
addDatesRange(dates.get(0).minusDays(1));
adapter.notifyDataSetChanged();
}
}
});
private void addDatesRange(DateTime end) {
DateTime start = end.minusDays(6); //end.minusYears(1);
String msg = String.format("addDatesRange: start = %s, end = %s", start.toString("dd.MM.yyyy"), end.toString("dd.MM.yyyy"));
System.out.println(msg);
dates.addAll(0, getDatesRange(start, end));
}
public static ArrayList<DateTime> getDatesRange(DateTime start, DateTime end) {
ArrayList<DateTime> result = new ArrayList<>();
while (start.isBefore(end)) {
result.add(start);
start = start.plusDays(1);
}
result.add(start);
return result;
}