0

我的列表视图中有 10 个新条目是从今天日期为 12-13-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;
    }
}
4

1 回答 1

1

你的代码:

        long msTime = System.currentTimeMillis();
        Date date = new Date(msTime);
        SimpleDateFormat sdf = new SimpleDateFormat("M/d/y");
        String biggie = sdf.format(date);

在呈现列表视图时调用。因此,您正在动态创建一个反映当前日期(即渲染时的日期)的新日期。

如果您想要一个永不更改的日期,请计算一次并保留它(SharedPreferences 将是一个不错的选择)。然后在以后的调用中,从 SharedPreferences 中读取日期字符串。

于 2013-12-13T18:22:11.243 回答