0
GetView方法正確設置數據。我檢查了我的mMessageList項目標籤並且膨脹了相應的佈局,但在滾動getView混合它們。我該如何解決這個問題?爲什麼getView混合我的行?
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder = null;
if(convertView == null){
viewHolder = new ViewHolder();
if(mMessageList.get(position).getTag() == RespKey.MESSAGE_TAG_CUSTOMER){
convertView = mInflater.inflate(R.layout.message_list_row_customer, null);
viewHolder.messageTextView = (TextView) convertView.findViewById(R.id.userMessageText);
viewHolder.messageImageView = (ImageView) convertView.findViewById(R.id.userMessageIcon);
} else {
convertView = mInflater.inflate(R.layout.message_list_row_driver, null);
viewHolder.messageTextView = (TextView) convertView.findViewById(R.id.driverMessageText);
viewHolder.messageImageView = (ImageView) convertView.findViewById(R.id.driverMessageIcon);
}
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.messageTextView.setText(mMessageList.get(position).getMessage());
return convertView;
}
public static class ViewHolder{
public TextView messageTextView;
public ImageView messageImageView;
}
我將返回0和1或RespKey.MESSAGE_TAG_CUSTOMER和RespKey.MESSAGE_TAG_DRIVER? – user1480210
如果RespKey.MESSAGE_TAG_CUSTOMER和RespKey.MESSAGE_TAG_DRIVER是int值爲0和1,則應返回常量。 – Blackbelt
謝謝,這是解決我的問題 – user1480210