This code is written to sort the hashmap monthwise but i am not able to understand completely. Can anyone explain this. Also i want to know if i am accessing hashmap correctly in for loop. monthAnalysis is the name of hashmap and month is key. Sorry i forgot to mention that i know that it adds the data to table creating rows dynamically. my problem is in first 4 lines of code.
public void addData1(TableLayout tableLayout, HashMap<String, MonthAnalysis> monthAnalysis) {
String[] sortedMonthList = (String[]) monthAnalysis.keySet().toArray();
Arrays.sort(sortedMonthList);
for (String month : sortedMonthList) {
/* Create a TableRow dynamically */
TableRow tr = new TableRow(this);
tr.setLayoutParams(new TableLayout.LayoutParams(
TableLayout.LayoutParams.MATCH_PARENT,
TableLayout.LayoutParams.WRAP_CONTENT));
addRowItem(tr, getMonth(month), 1.3f, Typeface.DEFAULT, Color.parseColor("#000000"), Gravity.LEFT);
addRowItem(tr, Long.toString(monthAnalysis.get(month).credit), 0.9f, Typeface.DEFAULT, Color.parseColor("#000000"), Gravity.RIGHT);
addRowItem(tr, Long.toString(monthAnalysis.get(month).debit), 1f, Typeface.DEFAULT, Color.parseColor("#000000"), Gravity.RIGHT);
//addRowItem(tr, convertDate(Long.parseLong(transaction.date)), 1.5f, Typeface.DEFAULT, Color.parseColor("#000000"), Gravity.RIGHT);
tableLayout.addView(tr, new TableRow.LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
}
}