我创建了一个应用程序,其中消息是从 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;
}
}'