ExpandableListView
ExpandableListView是ListView的子類,在普通的ListView上面進行擴張,把應用中的列表項分為幾組,每組裡又可以包含多個列表項
實現ExpandableListView的幾種方法
-
擴充套件BaseExpandableListAdapter實現 ExpandableListView
-
使用Simple ExpandableListView將兩個List包裝成 ExpandableListView
-
使用SimpleCursorTreeAdapter將Cursor資料包裝成 SimpleCursorTreeAdapter
常用的xml屬性
-
android:childDivider
-
android:childIndicator
-
android:groupIndicator
舉個例子: 擴充套件BaseExpandableListAdapter實現 ExpandableListView
那麼關鍵就是,實現四個方法
-
getGroupCount:返回包含的組列表項的數量
int[] logos = new int[] { R.drawable.p, R.drawable.z, R.drawable.t }; private String[] at = new String[] { "第一種", "第二種", "第三種"}; private String[][] arms = new String[][] { { "11", "12", "13", "14" }, { "21", "22", "23", "24" }, { "31", "32" , "33" } }; @Override public int getGroupCount() { return at.length; }
-
getGroupView:返回的View物件將作為元件列表項
@Override public View getGroupView(int groupPosition, boolean isExpanded,View convertView, ViewGroup parent) { LinearLayout ll = new LinearLayout(MainActivity.this); ll.setOrientation(0); ImageView logo = new ImageView(MainActivity.this); logo.setImageResource(logos[groupPosition]); ll.addView(logo); TextView textView = getTextView(); textView.setText(getGroup(groupPosition).toString()); ll.addView(textView); return ll; }
-
getChildrenCount:返回特定組子列表項的數量
@Override public int getChildrenCount(int groupPosition) { return arms[groupPosition].length; }
-
getChildView:返回的View物件將作為特定組,特定位置的子列表項
@Override public View getChildView(int groupPosition, int childPosition,boolean isLastChild, View convertView, ViewGroup parent) { TextView textView = getTextView(); textView.setText(getChild(groupPosition, childPosition) .toString()); return textView; }
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69917874/viewspace-2693270/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- ExpandableListView使用View
- 5.ExpandableListViewView
- Android開發之ExpandableListViewAndroidView
- Android中ExpandableListView中巢狀ListViewAndroidView巢狀
- Android ExpandableListView的簡單應用AndroidView
- 設定ExpandableListView右邊的箭頭View
- ExpandableListView實現二級列表的顯示View
- ListView與ExpandableListView設定分割線 dividerViewIDE
- expandableListView的divider該溶液顯示在黑色ViewIDE
- Android中ExpandableListView,每次只展示一個分組AndroidView
- Android ExpandableListView 帶有Checkbox的簡單應用AndroidView
- ExpandableListView控制元件使用中一些小問題的總結View控制元件