ExpandableListView 关于更新视图 刷新数据

注意事项

  1. 适配器 需继承自 BaseExpandableListAdapter
    ExpandableListView 关于更新视图 刷新数据_第1张图片
  2. 使用handler

关键代码

    public List group = null ;
    public String[][] groupItem = null;
    private Context mContext = null;
    private Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            notifyDataSetChanged();//更新数据
            super.handleMessage(msg);
        }     
    };
    //更新数据
    public ExaminedListViewAdapter(Context context , List group, String[][] groupItem) {
        this.group = group;
        this.groupItem = groupItem;
        this.mContext = context;
    }

    /*供外界更新数据的方法*/
    public void refresh(ExpandableListView expandableListView,int groupPosition){
        handler.sendMessage(new Message());
        //必须重新伸缩之后才能更新数据
        expandableListView.collapseGroup(groupPosition);
        expandableListView.expandGroup(groupPosition);
    }

你可能感兴趣的:(ExpandableListView 关于更新视图 刷新数据)