zoukankan      html  css  js  c++  java
  • Android BaseAdapter 类 重写模版

    BaseAdapter 需要实现的


    ① 继承类的构造方法

    ② public int getCount()

    ③ public Object  getItem(int position)

    ④ public long getItemId(int position)

    ⑤ public View getView(int position , View converView , ViewGroup parent)

        这个很重要,这个View 显示 某一指定位置的视图。


    模版如下:


    public class ImageAdapter extends BaseAdapter {
        private Context mContext;
    
        public ImageAdapter(Context c) {
            mContext = c;
        }
    
        public int getCount() {
            return mThumbIds.length;
        }
    
        public Object getItem(int position) {
            return null;
        }
    
        public long getItemId(int position) {
            return 0;
        }
    
        // create a new ImageView for each item referenced by the Adapter
        public View getView(int position, View convertView, ViewGroup parent) {
            ImageView imageView;
            if (convertView == null) {  // if it's not recycled, initialize some attributes
                ......
            } else {
                imageView = (ImageView) convertView;
            }
    
            imageView.setImageResource(mThumbIds[position]);
            return imageView;
        }
    
        // references to our images
        private Integer[] mThumbIds = {
                R.drawable.sample_2, R.drawable.sample_3,
        };
    }

  • 相关阅读:
    12月4日
    12月3日
    12月2日
    12月1日
    11月30日
    11月29日
    11月28日
    11月27日
    jquery mobile-按钮控件
    ap web
  • 原文地址:https://www.cnblogs.com/wangmingshuo/p/3323402.html
Copyright © 2011-2022 走看看