在我的应用程序中,我必须显示一个列表视图,其中显示Date和String值.一个Model类用于向Array列表提供值.Date.Date值是使用Adapter Class中Model类的值派生的.Have显示按日期升序排序的列表视图,并突出显示最接近当前date.highlight的视图.特定视图的背景颜色,其下一个大于或等于当前日期.
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, …Run Code Online (Sandbox Code Playgroud) 我是 Android 新手。我有一个要求,我有一个字段可以输入一个人的出生日期。成功选择后,我想返回从出生日期到当前日期的总月数。例如,如果我输入出生日期截至2012年10月19日,我想返回36(个月)。我搜索了这个,但没有找到任何适合我的要求的东西。这是我当前返回成功数据的代码,
private void showDate(int year, int month, int day) {
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(0);
cal.set(year, month, day);
Date date = cal.getTime();
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
if(System.currentTimeMillis() > date.getTime()) {
edtDate.setText(sdf.format(date));
LocalDate date1 = new LocalDate(date);
LocalDate date2 = new LocalDate(new java.util.Date());
PeriodType monthDay = PeriodType.yearMonthDayTime();
Period difference = new Period(date1, date2, monthDay);
int months = difference.getMonths();
months=months + 1;
System.out.println("16102015:Nunber of Months"+months);
}else{
Toast.makeText(mActivity,getResources().getString(R.string.date_validationmsg),Toast.LENGTH_LONG).show();
}
}
Run Code Online (Sandbox Code Playgroud)