ListAdapter for use with HiberDroid Criteria Results (Lists). : ListAdapter « UI « Android






ListAdapter for use with HiberDroid Criteria Results (Lists).

 
/*
 * Copyright 2010 Christian Matzat and others
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

//package net.matzat.android.hiberdroid.widget;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * ListAdapter for use with HiberDroid Criteria Results (Lists).
 *
 * @param <T>
 */
public abstract class GenericListAdapter<T> extends BaseAdapter {

    protected Context context;
    protected List<T> list;

    /**
     * Creates a new GenericListAdapter with an empty list.
     *
     * @param context the Android Context
     */
    public GenericListAdapter(Context context) {
        super();
        this.context = context;
        this.list = new ArrayList<T>();
    }

    /**
     * Creates a new GenericListAdapter with the specified list.
     *
     * @param context the Android Context
     * @param list    the List of items
     */
    public GenericListAdapter(Context context, List<T> list) {
        super();
        this.context = context;
        this.list = list;
    }

    /**
     * Get the number of items in the list.
     *
     * @return number of objects
     */
    public int getCount() {
        return list.size();
    }

    /**
     * Get the specified item from the list.
     *
     * @param i number of the item
     * @return item from the list
     */
    public T getItem(int i) {
        return list.get(i);
    }

    /**
     * Update Content of the list.
     *
     * @param list List to update
     */
    public void setList(List<T> list) {
        this.list = list;
        this.notifyDataSetChanged();
    }

    /**
     * Get id of this item. Overwrite this method and return the value of the objects id property.
     *
     * @param i number of the item
     * @return the id value of the item
     */
    public abstract long getItemId(int i);

    /**
     * Fills the View of a row with the item at the specified position.
     * Overwrite this method with your own implementation.
     *
     * @param i         number of the item
     * @param view      the View
     * @param viewGroup the ViewGroup
     * @return a View of the row
     */
    public abstract View getView(int i, View view, ViewGroup viewGroup);
}

   
  








Related examples in the same category

1.BaseExpandableListAdapter Demo
2.implements ListAdapter
3.extends BaseExpandableListAdapter
4.A list view example where the data comes from a cursor, and a SimpleCursorListAdapter is used to map each item to a two-line display.
5.A list view example where the data comes from a custom ListAdapter
6.A list view example where the data comes from a custom ListAdapter