title: Custom android adapter with generic class
body: <p>I'm trying to create a generic adapter in Android, so i can not write it over and over.</p>
  
  <p>The thing is,it's working, but it's not recycling very well, it displays what i want but when i scroll, it's not in the same order.</p>
  
  <pre><code>public class CustomListViewAdapter&lt;T&gt; extends BaseAdapter {
  
  private List&lt;T&gt; objects;
  private LayoutInflater inflater;
  private int resources;
  private AdapterCommand&lt;T&gt; listener;
  private ViewHolder h;
  
  public CustomListViewAdapter(Context context, List&lt;T&gt; objects,
          int resources, AdapterCommand&lt;T&gt; listener, ViewHolder h) {
      this.h = h;
      this.listener = listener;
      this.resources = resources;
      this.objects = objects;
      inflater = (LayoutInflater) context
              .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  }
  
  @Override
  public int getCount() {
      // TODO Auto-generated method stub
      return objects.size();
  }
  
  @Override
  public Object getItem(int position) {
      // TODO Auto-generated method stub
      return objects.get(position);
  }
  
  @Override
  public long getItemId(int position) {
      // TODO Auto-generated method stub
      return 0;
  }
  
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
      // TODO Auto-generated method stub
      View v = convertView;
      if (v == null) {
          v = inflater.inflate(resources, parent, false);
          listener.init(v, h);
          v.setTag(h);
      } else {
          h = (ViewHolder) v.getTag();
      }
      T object = (T) getItem(position);
      listener.execute(object, h);
      return v;
  }
  
  public interface AdapterCommand&lt;T&gt; {
      public void init(View v, ViewHolder h);
  
      public void execute(T object, ViewHolder h);
  }
  
  public static interface ViewHolder {
  
  }
  
  }
  </code></pre>