1. 设置ExpandableListView 默认是展开的:
先实例化exListView 然后
(exlvAdapter);
//遍历所有group,将所有项设置成默认展开
intgroupCount = ();
for (inti=0; i<groupCount; i++)
{
(i);
};
2. 去掉ExpandableListView 默认的箭头
用到ExpandableListView时有个箭头图标系统自带的在你自定义布局也不能去掉只要设置一个属性即可,如下:
(null); ~~~~~~~~~~~~~~~~~此处就是设置自定义的箭头图标的。置空则没有了。
也可以自定义(但是位置还是在那个地方不推荐)如下:
首先,自定义一个文件,具体内容如下: Java代码
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:andro>
<item android:state_expanded="true" android:drawable="@drawable/expandablelistviewindicatordown" />
<item android:drawable="@drawable/expandablelistviewindicator" />
</selector>
加一句代码如下:
(().getDrawable());
或xml设置:
android:groupIndicator="@drawable/groupIndicator_selector"
大功告成
1首先ExpandableListViewelistview;
(null);//将控件默认的左边箭头去掉,
2在自定义的继承自BaseExpandableListAdapter的adapter中有一个方法
/** * 父类view */ @Override
public View getGroupView(intgroupPosition, booleanisExpanded, View convertView, ViewGroup parent)
{ ("zhaoxiong","parent view");
LinearLayoutparentLayout=(LinearLayout) (context, .wowocoupons_parent_item, null);
TextViewparentTextView=(TextView)();
((groupPosition));
ImageViewparentImageViw=(ImageView) ();
//判断isExpanded就可以控制是按下还是关闭,同时更换图片
if(isExpanded){
(.arrow_down);
}else{
(.arrow_up); }
return parentLayout;
}
expandablelistview响应onGroupClick监听:设置()
折叠和展开事件,可以设置setOnGroupCollapseListener和setOnGroupExpandListener
ExpandableListView中包含多个group,想要展开一个group时,其他group都关闭:
(new OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
for (int i = 0; i < getData().size(); i++) {
if (groupPosition != i) {
(i);
}
}
}
});
的Group点击事件,onGroupClick的返回值false展开,true不展开
tt_list.setOnGroupClickListener(new OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View v,
int groupPosition, long id) {
IsFlag=true;
if(().get(groupPosition).getList().size()==1){
Bundle b=new Bundle();
("saveIndex", 0);
// ("mac", mac);
// ("deviceId", mDeviceId);
("datalist", ().get(groupPosition).getList());
Intent i=new Intent(,);
(b);
startActivity(i);
}
// int groupCount = tt_list.getCount();
// for (int i=0; i<groupCount; i++){
// if(i!=GroupPosition)
// tt_list.collapseGroup(i);
// };
// ("xulongheng*WappushBind*tt_list", "onGroupClick:"+previousX+"/"+previousY);
return true; //默认为false,设为true时,点击事件不会展开Group
}
});