ExpandableListView 關於更新視圖 刷新數據

注意事項

  1. 適配器 需繼承自 BaseExpandableListAdapter
  2. 使用handler

關鍵代碼

    public List<ExpandableGroupBean> 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<ExpandableGroupBean> 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);
    }
發佈了37 篇原創文章 · 獲贊 16 · 訪問量 8萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章