我的listview中有10个新条目从一个edittext动态添加,今天的日期为12-13-2013我无法弄清楚为什么明天所有的日期都会读到12-14-2013我希望每个条目保留日期进入并且没有改变任何想法?
class ViewHolder {
TextView gump;
ImageView pic;
TextView day;
ImageView more;
ViewHolder(View v) {
gump = (TextView) v.findViewById(R.id.inputLrgtxt);
pic = (ImageView)v.findViewById(R.id.sexpic);
day = (TextView)v.findViewById(R.id.holla);
}
}
private class KoreyzAdapter extends ArrayAdapter<ArgueItem> {
private ArrayList<ArgueItem> argueList;
private Context context;
public KoreyzAdapter(Context c, int textViewResourceId, ArrayList<ArgueItem> argueList) {
super(c, textViewResourceId, argueList);
this.argueList = argueList;
this.context = c;
}
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
ViewHolder holder = null;
long msTime = System.currentTimeMillis();
Date date = new Date(msTime);
SimpleDateFormat sdf = new SimpleDateFormat("M/d/y");
String biggie = sdf.format(date);
if(row == null) {
LayoutInflater inflator = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflator.inflate(R.layout.list_item, parent, false);
holder = new ViewHolder(row);
row.setTag(holder);
}
else {
holder = (ViewHolder)row.getTag();
}
holder.gump.setText(argueList.get(position));
holder.day.setText(biggie);
return row;
}
}
答案 0 :(得分:1)
您的代码:
long msTime = System.currentTimeMillis();
Date date = new Date(msTime);
SimpleDateFormat sdf = new SimpleDateFormat("M/d/y");
String biggie = sdf.format(date);
呈现列表视图时会调用。因此,您正在创建一个反映当前日期(即呈现时的日期)的新日期。
如果您想要一个永不改变的日期,请计算一次并坚持下去(SharedPreferences将是一个不错的选择)。然后在将来的调用中,从SharedPreferences中读取日期字符串。