exListView.setAdapter(exlvAdapter); //遍历所有group,将所有项设置成默认展开 intgroupCount = exListView.getCount(); for (inti=0; i<groupCount; i++) { exListView.expandGroup(i); };
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_expanded="true" android:drawable="@drawable/expandablelistviewindicatordown" /> <item android:drawable="@drawable/expandablelistviewindicator" /> </selector>
加一句代码如下:
settingLists.setGroupIndicator(this.getResources().getDrawable(R.layout.expandablelistviewselector)); 或xml设置: android:groupIndicator="@drawable/groupIndicator_selector"
大功告成
elistview.setGroupIndicator(null);//将控件默认的左边箭头去掉,
2在自定义的继承自BaseExpandableListAdapter的adapter中有一个方法
/** * 父类view */ @Override public View getGroupView(intgroupPosition, booleanisExpanded, View convertView, ViewGroup parent) { Log.i("zhaoxiong","parent view"); LinearLayoutparentLayout=(LinearLayout) View.inflate(context, R.layout.wowocoupons_parent_item, null); TextViewparentTextView=(TextView)parentLayout.findViewById(R.id.parentitem); parentTextView.setText(parentlist.get(groupPosition)); ImageViewparentImageViw=(ImageView) parentLayout.findViewById(R.id.arrow); //判断isExpanded就可以控制是按下还是关闭,同时更换图片 if(isExpanded){ parentImageViw.setBackgroundResource(R.drawable.arrow_down); }else{ parentImageViw.setBackgroundResource(R.drawable.arrow_up); } return parentLayout; }
exList.setOnGroupExpandListener(new OnGroupExpandListener() { @Override public void onGroupExpand(int groupPosition) { for (int i = 0; i < getData().size(); i++) { if (groupPosition != i) { exList.collapseGroup(i); } } } });3.expandablelistview的Group点击事件,onGroupClick的返回值false展开,true不展开
tt_list.setOnGroupClickListener(new OnGroupClickListener() { @Override public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) { IsFlag=true; if(adapter.getGroupData().get(groupPosition).getList().size()==1){ Bundle b=new Bundle(); b.putInt("saveIndex", 0); // b.putString("mac", mac); // b.putString("deviceId", mDeviceId); b.putSerializable("datalist", adapter.getGroupData().get(groupPosition).getList()); Intent i=new Intent(WappushBindingActivity.this,VideoPlayerActivity.class); i.putExtras(b); startActivity(i); } // int groupCount = tt_list.getCount(); // for (int i=0; i<groupCount; i++){ // if(i!=GroupPosition) // tt_list.collapseGroup(i); // }; // Log.v("xulongheng*WappushBind*tt_list", "onGroupClick:"+previousX+"/"+previousY); return true; //默认为false,设为true时,点击事件不会展开Group } });