zoukankan      html  css  js  c++  java
  • BaseAdapter

    package com.leamiko.common.widget.adapter;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.BaseAdapter;
    
    /**
     * Extents from BaseAdapter RTAdapter.java
     * 
     * @param <T>
     */
    public abstract class BaseAdapter<T> extends BaseAdapter {
    
            private List<T> mList = new ArrayList<T>();
    
            /**
             * Set data list to Adapter
             * 
             * @param list
             */
            protected void setList(List<T> list) {
                    if (list != null) {
                            mList.addAll(list);
                    } else {
                            throw new NullPointerException();
                    }
            }
    
            /**
             * Clear data list and reset it, update ListView
             * 
             * @param list
             */
            public void notifyDateSetUpdate(List<T> list) {
                    if (list != null && mList.size() > 0) {
                            mList.clear();
                            mList.addAll(list);
                            notifyDataSetChanged();
                    }
            }
    
            /**
             * Get data list
             * 
             * @return
             */
            public List<T> getList() {
                    return mList;
            }
    
            /**
             * Append data list to bottom of the ListView
             * 
             * @param list
             */
            public void appendToBottomList(List<T> list) {
                    if (list == null) {
                            return;
                    }
                    mList.addAll(list);
                    notifyDataSetChanged();
            }
    
            /**
             * Append data list to top of the ListView
             * 
             * @param list
             */
            public void appendToTopList(List<T> list) {
                    if (list == null) {
                            return;
                    }
                    mList.addAll(0, list);
                    notifyDataSetChanged();
            }
    
            /**
             * Clear all the data and update ListView
             */
            public void clear() {
                    mList.clear();
                    notifyDataSetChanged();
            }
    
            /* BaseAdapter methods */
            @Override
            public int getCount() {
                    return mList.size();
            }
    
            @Override
            public Object getItem(int position) {
                    if (position > mList.size() - 1) {
                            return null;
                    }
                    return mList.get(position);
            }
    
            @Override
            public long getItemId(int position) {
                    return position;
            }
    
            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                    return getItemView(position, convertView, parent);
            }
    
            /**
             * Custom item view in your subclass
             * 
             * @param position
             * @param convertView
             * @param parent
             * @return
             */
            protected abstract View getItemView(int position, View convertView,
                            ViewGroup parent);
    
    }
  • 相关阅读:
    epoll讲解
    Majority Element
    Excel Sheet Column Title
    Git链接到自己的Github(2)进阶使用
    Git链接到自己的Github(1)简单的开始
    直接管理内存
    Oracle 11g 编译使用BBED
    Oracle数据库该如何着手优化一个SQL
    Oracle配置数据库诊断
    Oracle 数据库重放(Database Replay)功能演示
  • 原文地址:https://www.cnblogs.com/leamiko/p/3510957.html
Copyright © 2011-2022 走看看