在我的應用程序中,我必須顯示一個列表視圖,其中顯示Date和一個String值。一個Model類用於向Array列表提供值。 Date.Date值是使用適配器類中的Model類的值派生的。具有顯示按日期升序排序的列表視圖,並突出顯示與當前日期最近的視圖。下一個大於或等於當前日期的特定視圖的背景顏色。如何按日期排序ListView項目
BaseAdapter類
private ArrayList<Model> mListItems;
private Activity mActivity;
private LayoutInflater mInflater;
private Integer[] mListIcons;
private Date DateOfBirth;
private int NumberOfMonths;
private ArrayList<Integer> SottList;
List<Date> dateList = new ArrayList<Date>();
public Adapter(Activity mActivity, Date DateOfBirth,ArrayList<VaccinationScheduleModel> mListItems) {
// super();
this.mActivity = mActivity;
this.mListItems=mListItems;
this.DateOfBirth=DateOfBirth;
mInflater = (LayoutInflater) mActivity.getLayoutInflater();
}
@Override
public int getCount() {
return mListItems.size();
}
@Override
public Object getItem(int position) {
return mListItems.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = mInflater.inflate(R.layout.custom_lv_vacc_schedule,
parent, false);
} else {
convertView = convertView;
}
String atrNumberOfMonths=mListItems.get(position).getmNumberOfMonths();
NumberOfMonths = Integer.parseInt(atrNumberOfMonths);
Calendar cal = Calendar.getInstance();
cal.setTime(DateOfBirth);
cal.add(Calendar.MONTH, NumberOfMonths);
Date result = cal.getTime();
dateList.add(result);
String dayOfTheWeek = (String) android.text.format.DateFormat.format("EEEE", result);//Thursday
String stringMonth = (String) android.text.format.DateFormat.format("MMM", result); //Jun
String intMonth = (String) android.text.format.DateFormat.format("MM", result); //06
String year = (String) android.text.format.DateFormat.format("yyyy", result); //2013
String day = (String) android.text.format.DateFormat.format("dd", result); //20
System.out.println("19102015:VaccinationScheduleAdapter" + result);
TextView txtVaccTitle = (TextView) convertView.findViewById(R.id.txtVaccTitle);
TextView txtVaccMonth = (TextView) convertView.findViewById(R.id.txtVaccMonth);
TextView txtVaccDay= (TextView) convertView.findViewById(R.id.txtVaccDay);
TextView txtVaccYear = (TextView) convertView.findViewById(R.id.txtVaccYear);
ImageView imgIcon = (ImageView) convertView.findViewById(R.id.imgIcon);
imgIcon.setBackgroundResource(R.drawable.calendar_icon);
txtVaccTitle.setText(mListItems.get(position).getmDescription());
txtVaccMonth.setText(stringMonth);
txtVaccDay.setText(day);
txtVaccYear.setText(year);
Collections.sort(dateList);
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
return convertView;
}
任何一個可以幫助我在此先感謝
如果你是從獲取數據庫中的數據,然後做出我不是你在使用使用數據庫 –
查詢? 從哪裏得到日期? –
是 –