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));