v.getTag () возвращает null вместо ViewHolder

У меня есть настраиваемый адаптер с заголовком и настраиваемыми строками. Иногда мой v.getTag () возвращает null, где я сохранил свой ViewHolder. Это происходит не всегда, и я не могу понять, когда и почему это происходит.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;

    //Header
    if(items.hasDescription() && 0 == position) {
        LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = vi.inflate(R.layout.app_list_header, null); 
        ((TextView) v.findViewById(R.id.app_list_header_description_text)).setText(items.getDescription());
        return v;
    }

    ViewHolder holder;
    // Inflate app view.
    if (v == null || v.getTag() == null) {
        LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = vi.inflate(textViewResourceId, null); //TODO: parent instead of null?
        holder = new ViewHolder();
        holder.title = (TextView) v.findViewById(R.id.title);
        holder.company = (TextView) v.findViewById(R.id.company);
        holder.priceOrStatus = (TextView) v.findViewById(R.id.price);
        holder.rating = (RatingBar) v.findViewById(R.id.rating);
        holder.icon = (ImageView) v.findViewById(R.id.icon);
        v.setTag(holder);
    } else {
        holder = (ViewHolder) v.getTag();
    }

}
    App app;
    if(items.hasDescription()) {
        app = items.get(position-1);    
    } else {
        app = items.get(position);
    }

    // TODO: Do we need this?
    if (null == app || null == holder) {
        Log.d(TAG, "app: " +app +" holder: " +holder);
        return v;
    }

    //TODO: FIX THE XML BEFORE SO WE DO NOT NEED TO TRIM IT.
    // And get rid of all these ifs!!
    if(holder.title != null) {
        holder.title.setText(app.getTitle().trim());                            

    }

Кто-нибудь может мне помочь?

20
задан Tobias Ekblom 22 July 2011 в 08:18
поделиться