ListView の 2 つの異なるレイアウトを膨らませています。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;
}
}