listView使用的万能的BaseAdapter

当使用Adapter时只需继承myAdapter实现getView()方法即可;

public abstract class myAdapter extends BaseAdapter{

    public Context mContext;
    public List mList;
//构造函数,将数据集合传递进来
    public <T> myAdapter(Context context,List<T> mList){
        this.mContext = context;
        this.mList = mList;        
    }
    @Override
    public int getCount() {
        return mList.size();
    }
    @Override
    public Object getItem(int position) {
        return position;
    }
    @Override
    public long getItemId(int position) {
        return 0;
    }
    //向外部暴露的接口.以便设置item
    public abstract View getView(int position, View convertView, ViewGroup parent);
}

当adapter中的list发生改变时.需要更新UI时调用 notifyDataSetChanged();

你可能感兴趣的:(继承,数据,ListView)