My application sources a list of dates and names from my Database and then displays the name in one card view and the date in another just above it and this continues for every record. I then decided that it makes sense for only one date to be shown for multiple records which share the same date.
Currently the code works correctly when I'm using a simple cursor but I'm wishing to move away from the cursor and use simple getters for the information.
I have added in the code below which is currently causing me issues and I have also commented in the original version which I used on my cursor adapter which works perfectly.
Thank you
if (position - 1 >= 0) {
String currentDate = alarmDetails.getAlarmDate();
String previousDate = alarmDetails.getAlarmDate();
// Cursor version
//String currentDate = cursor.getString(cursor.getColumnIndexOrThrow("complete_date"));
//cursor.moveToPosition(position - 1);
//String previousDate = cursor.getString(cursor.getColumnIndexOrThrow("complete_date"));
if (currentDate.equalsIgnoreCase(previousDate)) {
viewHolder.header.setVisibility(View.GONE);
viewHolder.cardView.setVisibility(View.GONE);
} else {
viewHolder.header.setVisibility(View.VISIBLE);
viewHolder.cardView.setVisibility(View.VISIBLE);
viewHolder.header.setText(currentDate);
}
} else {
viewHolder.header.setVisibility(View.VISIBLE);
viewHolder.cardView.setVisibility(View.VISIBLE);
viewHolder.header.setText(alarmDetails.getAlarmDate());
Cursor Version
//viewholder.header.setText(cursor.getString(cursor.getColumnIndexOrThrow("complete_date")));
}
}