0
我創建了一個應用程序,其中消息是從Web服務發送的。我在列表視圖中存儲響應。當列表中的響應保存在列表視圖中時,它給每行的同一時間,我想要不同的時間最新的時間,但更早的時間不會改變。請給我一些idea.The代碼如何獲得不同行的時間
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;
}
}'
發表一些代碼。如果您使用自定義適配器爲您的列表視圖,然後至少發佈其getView方法。 –