1
최근 전화 페이지가 있습니다. 최근 통화를 날짜 (MMMM DD, YYYY 형식)로 구분하고 싶지만 제대로 표시되지 않습니다. 마지막 세 항목이 2013 년 12 월 16 일, 2013 년 12 월 16 일, 2013 년 12 월 13 일인 경우에도 2013 년 12 월 17 일 첫 번째 날짜 만 표시됩니다.DateIndexer issue
여기 내 코드는 다음과 같습니다.
boolean needSeparator = false;
final int position = cursor.getPosition();
if(this.dateIndexer == null)
this.dateIndexer = new LinkedHashMap<String, Integer>();
sdf = new SimpleDateFormat("h:mm aa MMMM dd, yyyy", Locale.getDefault());
Date testDate;
try {
testDate = sdf.parse(date);
Calendar calDate = Calendar.getInstance();
calDate.setTime(testDate);
String day = String.valueOf(calDate.get(Calendar.DATE));
String month = calDate.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault());
String year = String.valueOf(calDate.get(Calendar.YEAR));
shortDate = month + " " + day + ", " + year;
if(!shortDate.equals(prDate)){
this.dateIndexer.put(shortDate, position);
prDate = shortDate;
}
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Set<String> sectionDates = this.dateIndexer.keySet();
// create a list from the set to sort
ArrayList<String> sectionList = new ArrayList<String>(sectionDates);
this.sections = new String[sectionList.size()];
sectionList.toArray(this.sections);
if (position == 0) {
needSeparator = true;
} else {
cursor.moveToPosition(position - 1);
cursor.copyStringToBuffer(RecentQuery.COLUMN_DATE, mBuffer);
if (mBuffer.sizeCopied > 0 && holder.dateBuffer.sizeCopied > 0 && mBuffer.data[0] != holder.dateBuffer.data[0]) {
needSeparator = true;
}
cursor.moveToPosition(position);
}
if (needSeparator) {
holder.separator.setText(sectionList.get(sectionList.size() - 1));
holder.separator.setVisibility(View.VISIBLE);
} else {
holder.separator.setVisibility(View.GONE);
}
도움이 될 것입니다. 고마워요