1. 設置ExpandableListView 默認是展開的: android
先實例化 exListView ide
而後 佈局
exListView.setAdapter(exlvAdapter); this
//遍歷全部group,將全部項設置成默認展開 spa
int groupCount = exListView.getCount(); .net
for (int i=0; i<groupCount; i++) { xml
exListView.expandGroup(i); blog
}; 繼承
2. 去掉ExpandableListView 默認的箭頭 圖片
用到ExpandableListView時有個箭頭圖標系統自帶的在你自定義佈局也不能去掉只要設置一個屬性便可,以下:
settingLists.setGroupIndicator(null); ~~~~~~~~~~~~~~~~~此處就是設置自定義的箭頭圖標的。置空則沒有了。
也能夠自定義(可是位置仍是在那個地方不推薦)以下:
首先,自定義一個expandablelistviewselector.xml文件,具體內容以下:
Java代碼
<?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));
大功告成
3. 將默認的箭頭修改到右邊顯示:
1首先 ExpandableListView elistview;
elistview.setGroupIndicator(null);//將控件默認的左邊箭頭去掉,
2在 自定義的繼承自BaseExpandableListAdapter的adapter中有一個方法
/**
* 父類view
*/
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
Log.i("zhaoxiong","parent view");
LinearLayout parentLayout=(LinearLayout) View.inflate(context, R.layout.wowocoupons_parent_item, null);
TextView parentTextView=(TextView) parentLayout.findViewById(R.id.parentitem);
parentTextView.setText(parentlist.get(groupPosition));
ImageView parentImageViw=(ImageView) parentLayout.findViewById(R.id.arrow);
//判斷isExpanded就能夠控制是按下仍是關閉,同時更換圖片
if(isExpanded){ parentImageViw.setBackgroundResource(R.drawable.arrow_down); }else{ parentImageViw.setBackgroundResource(R.drawable.arrow_up); } return parentLayout; }