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, }; }