0

我创建了一个应用程序,其中消息是从 Web 服务发送的。我将响应存储在列表视图中。当响应保存在列表视图中时,它为每一行提供相同的时间,我想要不同的最新时间,但较旧的时间不会改变。请给我一些想法。代码是

    public class WebMessageAdapter extends ArrayAdapter<WebMessageCore>{

        Context _Context;
        ArrayList<WebMessageCore> _WebMsgList;
        WebMessageCore _WebMsgCore;
        TextView _MsgContent;
        private LayoutInflater mInflater;
        ImageButton Arrow;
        GabrielApplication application;
        public WebMessageAdapter(Context context, int resource,
         ArrayList<WebMessageCore> contactList) {
            super(context, resource,  contactList);
            _Context = context;
            _WebMsgList = contactList;
            mInflater = LayoutInflater.from(context);
        }

        public int getCount() {
            return _WebMsgList.size();
        }

        public WebMessageCore getItem(int position) {
            return _WebMsgList.get(position);
        }

        public long getItemId(int position) {
            return position;
        }


        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder holder;
            if (convertView == null) {
                convertView = mInflater.inflate(R.layout.custom_row_view, null);
                holder = new ViewHolder();
                holder.txtName = (TextView) convertView.findViewById(R.id.name);
                holder.txtmessage = (TextView) convertView.findViewById(R.id.meassage);
                holder.txtPhone = (TextView) convertView.findViewById(R.id.phone);
                holder.txtdate=  (TextView ) convertView.findViewById(R.id.datetime);
               //holder.Arrow =  (ImageButton)convertView.findViewById(R.id.settingArrow);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }

            _WebMsgCore=_WebMsgList.get(position);
            holder.txtName.setText(_WebMsgCore.getName());
            holder.txtmessage.setText(_WebMsgCore.getMessage());
           holder.txtPhone.setText(_WebMsgCore.getMobileNo());
           Arrow.setOnClickListener(new OnClickListener(){

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub

                    Intent newActivity =  new Intent(_Context, ContactInfoActivity.class);
                    _Context.startActivity(newActivity);
            /*      
            Intent intent = new Intent(_Context, ContactInfoActivity.class);
                    GabrielUtil.replaceContentView(application.getGroupContext(),
                            GBConstants.contact_info, intent);*/
                }
            });

           String currentDateTimeString = DateFormat.getDateTimeInstance().format(new Date());
           holder.txtdate.setText(currentDateTimeString);
            return convertView;



        }


        static class ViewHolder {
            TextView txtName;
            TextView txtmessage;
            TextView txtPhone;
            TextView txtdate;
            ImageButton Arrow;
        }
    }'
4

1 回答 1

0

线上的实际问题

String currentDateTimeString = DateFormat.getDateTimeInstance().format(new Date());

上面的行给出了相同的日期格式,例如 2012 年 5 月 9 日下午 4:36:12。因为该getView()方法在我的电脑上在 650 毫秒内执行,结果相同。时间可能会因电脑的配置而异。所以你可以尝试使用替换上面的行

        SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm:ss.SSS a");
        Date resultdate = new Date((new Date()).getTime());
        String currentDateTimeString = sdf.format(resultdate);
于 2012-05-09T11:26:26.157 回答