ExpandableListView: 需要继承 BaseExpandableListAdapter 设置适配器

默认有下拉收缩箭头,可以自定义样式-- android:state_expanded = "true"

注意如果子类布局中如:checkbox 的要设置不获取焦点,否则可能会点击组无效

<ExpandableListView        android:id="@+id/grow_scgrade_exlist"        android:layout_width="match_parent"       <span style="color:#993300;"> <strong>android:groupIndicator="@null"</strong></span>        android:layout_height="match_parent" >    </ExpandableListView>


父类布局

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:orientation="vertical" >    <TextView        android:id="@+id/item_grow_parent_txt"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:paddingBottom="5dp"        android:paddingLeft="10dp"        android:paddingTop="5dp"        android:textSize="20sp" /></LinearLayout>

子类布局

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:orientation="vertical" >    <TextView        android:id="@+id/item_grow_child_txt"        android:layout_width="match_parent"        android:layout_height="wrap_content"         android:paddingLeft="10dp"        android:paddingTop="5dp"        android:paddingBottom="5dp"        android:textSize="18sp" /></LinearLayout>



public class MyExpandAdapter extends BaseExpandableListAdapter {private List<String> parent = new ArrayList<String>();private List<List<String>> child = new ArrayList<List<String>>();private LayoutInflater inflater;<span style="white-space:pre"></span>//设置数据源public void setData(List<String> parent, List<List<String>> child) {this.parent = parent;this.child = child;notifyDataSetChanged();}public MyExpandAdapter(Context context) {inflater = LayoutInflater.from(context);}@Overridepublic int getGroupCount() {return parent.size();}@Overridepublic int getChildrenCount(int groupPosition) {return child.get(groupPosition).size();}@Overridepublic Object getGroup(int groupPosition) {return parent.get(groupPosition);}@Overridepublic Object getChild(int groupPosition, int childPosition) {return child.get(groupPosition).get(childPosition);}@Overridepublic long getGroupId(int groupPosition) {return groupPosition;}@Overridepublic long getChildId(int groupPosition, int childPosition) {return childPosition;}@Overridepublic boolean hasStableIds() {return false;}/* * 父类布局 */@Overridepublic View getGroupView(int groupPosition, boolean isExpanded,View convertView, ViewGroup parent) {TextView txt;if (convertView == null) {convertView = inflater.inflate(R.layout.item_grow_grade1_layout, parent, false);txt = (TextView) convertView.findViewById(R.id.item_grow_parent_txt);convertView.setTag(R.id.item_grow_parent_txt, txt);} else {txt = (TextView) convertView.getTag(R.id.item_grow_parent_txt);}txt.setText((CharSequence) getGroup(groupPosition));return convertView;}/* * 子类布局 */@Overridepublic View getChildView(int groupPosition, int childPosition,boolean isLastChild, View convertView, ViewGroup parent) {TextView txt;if (convertView == null) {convertView = inflater.inflate(R.layout.item_grow_grade2_layout, null);txt = (TextView) convertView.findViewById(R.id.item_grow_child_txt);convertView.setTag(R.id.item_grow_child_txt, txt);} else {txt = (TextView) convertView.getTag(R.id.item_grow_child_txt);}txt.setText((String) getChild(groupPosition, childPosition));return convertView;}@Overridepublic boolean isChildSelectable(int groupPosition, int childPosition) {return true;}}



更多相关文章

  1. [Android]设置Activity为全屏显示的两种方法
  2. Android系统属性SystemProperties分析
  3. ListView去掉中间的分割线和设置Item之间的间距
  4. 高通平台android9.0设置开机默认横屏显示
  5. Android上传图片(PHP服务器)
  6. android沉浸式状态栏底部背景用图片代替
  7. arcgis for Android(安卓)100.2 加载shp
  8. android selector下的设置背景属性值
  9. Android(安卓)设置EditText光标Curso颜色及粗细

随机推荐

  1. Android入门(9)AudioRecord和AudioTrack类
  2. 【Android】adapter has changed解决方法
  3. 利用drozer进行Android渗透测试
  4. mac 不识别 android samsung手机
  5. Android(安卓)Studio插件之Android(安卓)
  6. Android(安卓)UI开发第七篇之Android(安
  7. Android屏幕的控制
  8. Android(安卓)解决setRequestedOrientati
  9. 关于Ant编译Android中Ant学习研究
  10. 花样Android(安卓)ProgressBar 史上最强