关于expandListview去掉标题,图标的在右边显示,,默认展开

1. 设置ExpandableListView 默认是展开的: 
先实例化exListView 然后 

[java]  view plain copy
  1. exListView.setAdapter(exlvAdapter);   
  2. //遍历所有group,将所有项设置成默认展开  
  3.  intgroupCount = exListView.getCount();   
  4. for (inti=0; i<groupCount; i++)  
  5.  {   
  6.        exListView.expandGroup(i);  
  7.  };   


2. 去掉ExpandableListView 默认的箭头 
用到ExpandableListView时有个箭头图标系统自带的在你自定义布局也不能去掉只要设置一个属性即可,如下: 
settingLists.setGroupIndicator(null); ~~~~~~~~~~~~~~~~~此处就是设置自定义的箭头图标的。置空则没有了。  
也可以自定义(但是位置还是在那个地方不推荐)如下: 
首先,自定义一个expandablelistviewselector.xml文件,具体内容如下: Java代码 
[html]  view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>   
  2. <selector xmlns:android="http://schemas.android.com/apk/res/android">   
  3.      <item android:state_expanded="true" android:drawable="@drawable/expandablelistviewindicatordown" />   
  4.       <item android:drawable="@drawable/expandablelistviewindicator" />  
  5.  </selector>   

加一句代码如下: 

[java]  view plain copy
  1. settingLists.setGroupIndicator(this.getResources().getDrawable(R.layout.expandablelistviewselector));    
  2. 或xml设置:  
  3.     android:groupIndicator="@drawable/groupIndicator_selector"  


大功告成 


3. 将默认的箭头修改到右边显示: 
 
1首先ExpandableListViewelistview;  

elistview.setGroupIndicator(null);//将控件默认的左边箭头去掉,

 2在自定义的继承自BaseExpandableListAdapter的adapter中有一个方法

[java]  view plain copy
  1. /** * 父类view */ @Override   
  2. ublic View getGroupView(intgroupPosition, booleanisExpanded, View convertView, ViewGroup parent)  
  3. { Log.i("zhaoxiong","parent view");   
  4.      LinearLayoutparentLayout=(LinearLayout) View.inflate(context, R.layout.wowocoupons_parent_item, null);   
  5.     TextViewparentTextView=(TextView)parentLayout.findViewById(R.id.parentitem);  
  6.     parentTextView.setText(parentlist.get(groupPosition));   
  7.     ImageViewparentImageViw=(ImageView) parentLayout.findViewById(R.id.arrow);   
  8.     //判断isExpanded就可以控制是按下还是关闭,同时更换图片  
  9.    if(isExpanded){   
  10.        parentImageViw.setBackgroundResource(R.drawable.arrow_down);   
  11.     }else{   
  12.         parentImageViw.setBackgroundResource(R.drawable.arrow_up); }    
  13.      return parentLayout;  
  14. }  

expandablelistview响应onGroupClick监听:设置expandablelistview.setOnGroupClickListener()
折叠和展开事件,可以设置setOnGroupCollapseListener和setOnGroupExpandListener


ExpandableListView中包含多个group,想要展开一个group时,其他group都关闭:
[java]  view plain copy
  1. exList.setOnGroupExpandListener(new OnGroupExpandListener() {    
  2.     
  3.         @Override    
  4.         public void onGroupExpand(int groupPosition) {    
  5.             for (int i = 0; i < getData().size(); i++) {    
  6.                 if (groupPosition != i) {    
  7.                     exList.collapseGroup(i);    
  8.                 }    
  9.             }    
  10.     
  11.         }    
  12.     
  13.     });  
3.expandablelistview的Group点击事件,onGroupClick的返回值false展开,true不展开

[java]  view plain copy
  1.          tt_list.setOnGroupClickListener(new OnGroupClickListener() {  
  2.               
  3.             @Override  
  4.             public boolean onGroupClick(ExpandableListView parent, View v,  
  5.                     int groupPosition, long id) {  
  6.                 IsFlag=true;  
  7.   
  8.                 if(adapter.getGroupData().get(groupPosition).getList().size()==1){  
  9.                     Bundle b=new Bundle();  
  10.                     b.putInt("saveIndex"0);  
  11. //                  b.putString("mac", mac);  
  12. //                  b.putString("deviceId", mDeviceId);  
  13.                     b.putSerializable("datalist", adapter.getGroupData().get(groupPosition).getList());  
  14.                     Intent i=new Intent(WappushBindingActivity.this,VideoPlayerActivity.class);  
  15.                     i.putExtras(b);   
  16.                     startActivity(i);  
  17.                 }  
  18. //              int groupCount = tt_list.getCount();     
  19. //              for (int i=0; i<groupCount; i++){     
  20. //                  if(i!=GroupPosition)  
  21. //                      tt_list.collapseGroup(i);    
  22. //               };   
  23. //              Log.v("xulongheng*WappushBind*tt_list", "onGroupClick:"+previousX+"/"+previousY);  
  24.                 return true;   //默认为false,设为true时,点击事件不会展开Group  
  25.             }  
  26.         });  

你可能感兴趣的:(关于expandListview去掉标题,图标的在右边显示,,默认展开)