• 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);
    
    }
  • 相关阅读:
    PyCharm下载和安装教程(包含配置Python解释器)
    C#解压、压缩RAR文件
    使用ADSI获取IIS版本
    SqlCommand.Parameters其实是用的存储过程sp_executesql
    C#将文件从指定的目录复制到另一个目录
    C#如何获取快捷方式指向的目标文件
    winform程序未捕获异常解决方法 EventType clr20r3 P1
    WebClient 下载文件
    获取所有的用户表
    C#操作IIS回收应用程序池,兼容iis6和iis7
  • 原文地址:https://www.cnblogs.com/leamiko/p/3510957.html
Copyright © 2020-2023  润新知