效果图
代码示例
GroupListActivity .java
public class GroupListActivity extends BaseActivity{
@InjectView(R.id.elv_teacher_grade)
ExpandableListView mGradeElv ;
private List<SchoolGradeInfo> mGradeList = new ArrayList<>();
TeacherGradeAdapter mGradeAdapter ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ButterKnife.inject(this);
//年级、班级
mGradeAdapter = new TeacherGradeAdapter(mContext,mGradeList,this) ;
mGradeElv.setAdapter(mGradeAdapter);
//去掉父列表箭头
mGradeElv.setGroupIndicator(null);
}
}
TeacherGradeAdapter.java
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.CheckBox;
import android.widget.TextView;
import com.yiw.circledemo.bean.SchoolClassInfo;
import com.yiw.circledemo.bean.SchoolGradeInfo;
import java.util.List;
/**
* 年级/班级 多级列表适配器
*
* Created by 万紫辉 on 2017/6/13 0013
* Email:wzhghgg@gmail.com
*/
public class TeacherGradeAdapter extends BaseExpandableListAdapter {
private Context mContext;
private LayoutInflater mInflater;
private List<SchoolGradeInfo> mData ;
public TeacherGradeAdapter(Context context, List<SchoolGradeInfo> list) {
mContext = context ;
mInflater = LayoutInflater.from(context);
mData = list ;
}
@Override
public int getGroupCount() {
return mData.size();
}
@Override
public int getChildrenCount(int groupPosition) {
return mData.get(groupPosition).getClassInfoList().size();
}
@Override
public Object getGroup(int groupPosition) {
return mData.get(groupPosition);
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return mData.get(groupPosition).getClassInfoList().get(childPosition);
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public boolean hasStableIds() {
return true;
}