ExpandableListView(手风琴)(1)---BaseExpandableListAdapter

来源:互联网 发布:oracle数据库的端口号 编辑:程序博客网 时间:2024/05/16 11:15
  • 基础属性
    groupIndicator 组左侧的箭头
  • 事件

适配器处理

  • 自定义抽象适配器继承BaseExpandableListAdapter 重写构造方法
//此处为public便于子类使用 获取控件public  LayoutInflater mInflater;     Context mContext;     List<String> group;     List<List<T>> child;public  SJXBaseAdapter(Context context){        mContext=context;        mInflater=LayoutInflater.from(context);}

添加数据方法

public void addData(List<String> group,List<List<T>> child){        this.group=group;        this.child=child;}

两个抽象方法在getView中调用

public abstract View getGrougView(int groupPosition,View convertView);public abstract View getChildView(int groupPosition,int childPosition,View convertView);@Override    public View getGroupView(int arg0, boolean arg1, View arg2, ViewGroup arg3) {        return getGrougView(arg0, arg2);}@Overridepublic View getChildView(int arg0, int arg1, boolean arg2, View arg3,ViewGroup arg4) {    return getChildView(arg0, arg1, arg3);}
  • 自定义适配器继承上面的适配器
    继承上述适配器 重写 构造方法 抽象方法
public LocalAdapter(Context context) {        super(context);    }@Override    public View getChildView(int groupPosition, int childPosition,            View convertView) {        View childView=mInflater.from(context).inflate(布局文件id, null);        TextView txtChild=(TextView) childView.findViewById(R.id.txt_child);        txtChild.setText(child.get(groupPosition).get(childPosition));        txtChild.setPadding(0, 0, 0, 0);        return childView;    }
  • 适配器关联activity
LocalAdapter ap=new LocalAdapter(this);ap.addData(list<>,list<list<String>>);activity.setAdapter(ap);
  • 补充
    适配器中getchild方法可以返回cursor
阅读全文
0 0