I am using SingleLine chart from PhilJay/MPAndroidChart android library and i need a list of passed months of current year. So for example from Jan to Oct, but when is October pass then from Jan to Nov and so on. I tried these: Getting List of Month for Past 1 year in Android dynamically, and Calculate previous 12 months from given month - SimpleDateFormat but all of these are for previosly 12 months and i want from start of current year
@SuppressLint("SimpleDateFormat")
private void handleXAxis() {
List<String> allDates = new ArrayList<>();
String maxDate = "Jan";
SimpleDateFormat monthDate = new SimpleDateFormat("MMM");
Calendar cal = Calendar.getInstance();
try {
cal.setTime(Objects.requireNonNull(monthDate.parse(maxDate)));
} catch (ParseException e) {
e.printStackTrace();
}
for (int i = 1; i <= 12; i++) {
String month_name1 = monthDate.format(cal.getTime());
allDates.add(month_name1);
cal.add(Calendar.MONTH, -1);
}
}