这是我的代码
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.email_list_main);
emailResults = new ArrayList<GetEmailFromDatabase>();
//int[] colors = {0,0xFFFF0000,0};
//getListView().setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors));
//getListView().setDividerHeight(2);
emailListFeedAdapter = new EmailListFeedAdapter(this, R.layout.email_listview_row, emailResults);
setListAdapter(this.emailListFeedAdapter);
getResults();
if(emailResults != null && emailResults.size() > -1){
emailListFeedAdapter.notifyDataSetChanged();
for(int i=0;i< emailResults.size();i++){
try {
在这里我收到电子邮件发送日期
emailListFeedAdapter.add( emailResults.get(i));
datetime_text1 = emailResults.get(i).getDate();
formatter1 = new SimpleDateFormat();
formatter1 = DateFormat.getDateInstance((DateFormat.MEDIUM));
Calendar currentDate1 = Calendar.getInstance();
Item_Date1 = formatter1.parse(datetime_text1);
current_Date1 = formatter1.format(currentDate1.getTime());
current_System_Date1 = formatter1.parse(current_Date1);
currentDate1.add(Calendar.DATE, -1);
yesterdaydate = formatter1.format(currentDate1.getTime());
yeaterday_Date = formatter1.parse(yesterdaydate);
currentDate1.add(Calendar.DATE, -2);
threeDaysback = formatter1.format(currentDate1.getTime());
Three_Days_Back = formatter1.parse(threeDaysback);
在这里,我将当前日期与列表视图项目日期进行比较,这是我的问题,日期匹配但它没有添加分隔符我尝试了很多方法但没有任何效果,分隔符的代码如下。
if(Item_Date.compareTo(current_System_Date)==0){
if(index1){
emailListFeedAdapter.addSeparatorItem("SEPARATOR");
//i--;
index1=false;
}
}
else if(yeaterday_Date.compareTo(Item_Date1)==0){
if(index2){
emailListFeedAdapter.addSeparatorItem("SEPARATOR");
//i--;
index2 = false;
}
}
else if(Item_Date1.compareTo(Three_Days_Back)==0){
if(index3){
emailListFeedAdapter.addSeparatorItem("SEPARATOR");
//i--;
index3 = false;
}
}
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
在 EmailListFeedAdapter 中
private TreeSet<Integer> mSeparatorsSet = new TreeSet<Integer>();
public void addSeparatorItem(final String item) {
//itemss.add(emailResults.get(0));
// save separator position
mSeparatorsSet.add(itemss.size() - 1);
notifyDataSetChanged();
}
@Override
public int getItemViewType(int position) {
return mSeparatorsSet.contains(position) ? TYPE_SEPARATOR : TYPE_ITEM;
}
holder = new ViewHolder();
switch (type) {
case TYPE_ITEM:
emailView= inflater.inflate(R.layout.email_listview_row, null);
break;
case TYPE_SEPARATOR:
emailView= inflater.inflate(R.layout.item2, null);
holder.textView = (TextView)emailView.findViewById(R.id.textSeparator);
emailView.setTag(holder);
holder.textView.setText("SEPARATOR");
break;
}
这是 ViewHolder 类
public static class ViewHolder {
public TextView textView;
}
如果有人知道,请告诉我我做错了什么。
谢谢