ExpandableListView設置自動展開

ExpandableListView分爲兩級list,設置自動展開需要調用expandableList.expandGroup(int pos)方法,該方法需寫在Activity onResume方法中,否則會報錯。

代碼如下:

private ExpandableListView expandableList;

private ListAdapter listadapter;

public void onResume() {
        super.onResume();
        //設置自動展開
        //自動展開必須寫在onResume方法中,否則會發生錯誤
        for (int i = 0; i < listadapter.getGroupCount(); i++) {
            expandableList.expandGroup(i);
        }

//將ExpandableListView groupitem中系統自帶的下拉箭頭圖標去掉
        expandableList.setGroupIndicator(null);
    }

在ListAdapter的getGroupView方法中加入

convertView.setClickable(true);即可設置爲groupitem不能點擊,實現保持兩級list一直展開的狀態。


GroupIndicator也可自定義xml,具體方法如下:

定義一個expandablelistviewselector.xml,id爲expandablelistviewselector,在onResume中加入代碼

expandableList.setGroupIndicator(this.getResources().getDrawable(R.layout.expandablelistviewselector));


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章