我正在为 ListView 充气两种不同的布局。一切正常,直到我开始向下滚动 2 个不同的布局开始随机应用。我在这里遵循了其他示例,但我无法让它工作。有什么建议么?
public class CustomAdapter extends BaseAdapter {
Date date = new Date();
private OfferList[] offers;
private String nameCompare = "";
CustomAdapter (OfferList[] offers, FetchItemsTask fetchItemsTask) {
this.offers = offers;
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
ViewHolder holder = null;
LayoutInflater inflater = getLayoutInflater();
if (convertView == null) {
holder = new ViewHolder();
if (nameCompare.equalsIgnoreCase(offers[position].getCustomerName())) {
convertView = inflater.inflate(R.layout.list_offer_group, null);
}
else {
nameCompare = offers[position].getCustomerName();
convertView = inflater.inflate(R.layout.list_offer, null);
}
holder.name = (TextView) convertView.findViewById(R.id.name);
holder.color = (TextView) convertView.findViewById(R.id.color_stock);
holder.time = (TextView) convertView.findViewById(R.id.time);
holder.offerStatus = (TextView) convertView.findViewById(R.id.offer_status);
convertView.setTag(holder);
}
else {
holder = (ViewHolder) convertView.getTag();
}
holder.name.setText(offers[position].getName());
holder.carStockColor.setText(offers[position].getYear() + " " + offers[position].getVehicleMake());
java.util.Date time1 = new java.util.Date(Long.parseLong(offers[position].getModified()));
holder.time.setText(time1.toString().substring(0, 11) + " | ");
holder.offerStatus.setText(offers[position].getStatus());
return convertView;
}
public class ViewHolder {
TextView name;
TextView color;
TextView time;
TextView offerStatus;
}
}