Android Open Source - FeedListViewDemo Simple Base Adapter






From Project

Back to project page FeedListViewDemo.

License

The source code is released under:

MIT License

If you think the Android project FeedListViewDemo listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package io.bxbxbai.androiddemos.adapter;
// w w w  . j av a 2s  .c o  m
import android.content.Context;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

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

/**
 *
 * Created by baia on 14-9-21.
 */
public abstract class SimpleBaseAdapter<T> extends BaseAdapter {

    protected List<T> mDataList;
    protected Context mContext;
    protected LayoutInflater mInflater;

    public SimpleBaseAdapter(Context context, List<T> dataList) {
        if (context == null) {
            throw new IllegalArgumentException("context Can NOT be null!");
        }
        if (mDataList == null) {
            throw new IllegalArgumentException("dataList Can NOT be null!");
        }
        mContext = context;
        mDataList = dataList;
        mInflater = LayoutInflater.from(context);
    }

    public SimpleBaseAdapter(Context context) {
        this(context, new ArrayList<T>());
    }

    @Override
    public int getCount() {
        return mDataList.size();
    }

    @Override
    public Object getItem(int position) {
        if (position >= mDataList.size()) {
            return null;
        }
        return mDataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position ;
    }

    /**
     * ????id
     * @return id
     */
    public abstract int getItemResourceId();

    /**
     *
     * @param position
     * @param convertView
     * @param holder
     * @return
     */
    public abstract View getItemView(int position, View convertView, ViewHolder holder);


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (null == convertView) {
            convertView = mInflater.inflate(getItemResourceId(), parent, false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        return getItemView(position, convertView, viewHolder);
    }

    public void addAll(List<T> elem) {
        mDataList.addAll(elem);
        notifyDataSetChanged();
    }

    public void remove(T data) {
        mDataList.remove(data);
        notifyDataSetChanged();
    }

    public void remove(int id) {
        mDataList.remove(id);
        notifyDataSetChanged();
    }

    public void replaceAll(List<T> elem) {
        mDataList.clear();
        mDataList.addAll(elem);
        notifyDataSetChanged();
    }


    public class ViewHolder {
        private SparseArray<View> views = new SparseArray<View>();
        private View convertView;

        public ViewHolder(View convertView) {
            this.convertView = convertView;
        }

        @SuppressWarnings("unchecked")
        public <T extends View> T getView(int id) {
            View v = views.get(id);
            if (null == v) {
                v = convertView.findViewById(id);
                views.put(id, v);
            }
            return (T)v;
        }
    }
}




Java Source Code List

com.android.volley.AuthFailureError.java
com.android.volley.CacheDispatcher.java
com.android.volley.Cache.java
com.android.volley.DefaultRetryPolicy.java
com.android.volley.ExecutorDelivery.java
com.android.volley.NetworkDispatcher.java
com.android.volley.NetworkError.java
com.android.volley.NetworkResponse.java
com.android.volley.Network.java
com.android.volley.NoConnectionError.java
com.android.volley.ParseError.java
com.android.volley.RequestQueue.java
com.android.volley.Request.java
com.android.volley.ResponseDelivery.java
com.android.volley.Response.java
com.android.volley.RetryPolicy.java
com.android.volley.ServerError.java
com.android.volley.TimeoutError.java
com.android.volley.VolleyError.java
com.android.volley.VolleyLog.java
com.android.volley.toolbox.AndroidAuthenticator.java
com.android.volley.toolbox.Authenticator.java
com.android.volley.toolbox.BasicNetwork.java
com.android.volley.toolbox.ByteArrayPool.java
com.android.volley.toolbox.ClearCacheRequest.java
com.android.volley.toolbox.DiskBasedCache.java
com.android.volley.toolbox.HttpClientStack.java
com.android.volley.toolbox.HttpHeaderParser.java
com.android.volley.toolbox.HttpStack.java
com.android.volley.toolbox.HurlStack.java
com.android.volley.toolbox.ImageLoader.java
com.android.volley.toolbox.ImageRequest.java
com.android.volley.toolbox.JsonArrayRequest.java
com.android.volley.toolbox.JsonObjectRequest.java
com.android.volley.toolbox.JsonRequest.java
com.android.volley.toolbox.NetworkImageView.java
com.android.volley.toolbox.NoCache.java
com.android.volley.toolbox.PoolingByteArrayOutputStream.java
com.android.volley.toolbox.RequestFuture.java
com.android.volley.toolbox.StringRequest.java
com.android.volley.toolbox.Volley.java
io.bxbxbai.androiddemos.AppController.java
io.bxbxbai.androiddemos.ApplicationTest.java
io.bxbxbai.androiddemos.MainActivity.java
io.bxbxbai.androiddemos.activity.BaseActivity.java
io.bxbxbai.androiddemos.activity.FeedListActivity.java
io.bxbxbai.androiddemos.adapter.FeedListAdapter.java
io.bxbxbai.androiddemos.adapter.SimpleBaseAdapter.java
io.bxbxbai.androiddemos.data.FeedItem.java
io.bxbxbai.androiddemos.data.FeedResult.java
io.bxbxbai.androiddemos.utils.BitmapUtils.java
io.bxbxbai.androiddemos.utils.GsonRequest.java
io.bxbxbai.androiddemos.utils.ListViewUtils.java
io.bxbxbai.androiddemos.utils.LruBitmapCache.java
io.bxbxbai.androiddemos.utils.RequestManager.java
io.bxbxbai.androiddemos.utils.TaskUtils.java
io.bxbxbai.androiddemos.utils.ToastUtils.java
io.bxbxbai.androiddemos.utils.VersionUtils.java
io.bxbxbai.androiddemos.utils.ViewFinder.java
io.bxbxbai.androiddemos.view.FeedImageView.java