Create or recycle View inside a listview. - Android android.widget

Android examples for android.widget:ListView

Description

Create or recycle View inside a listview.

Demo Code

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;

public class Main{

    /**//from w w w.  java2  s.  c  o m
     * Create or recycle View inside a listview.
     * 
     * @param c : Android context.
     * @param v : list view item.
     * @param layoutId : Unique identifier for the ressource layout.
     * @return a new or recycled item.
     */
    public static View recycleOrCreateView(Context c, View v, int layoutId) {
        if (v == null) {
            LayoutInflater vi = (LayoutInflater) c
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(layoutId, null);
            GenericViewHolder vh = new GenericViewHolder(v);
            v.setTag(vh);
        }
        return v;
    }

}

Related Tutorials