ListView之BaseExpandableListAdapter

来源:互联网 发布:电梯安全员考试软件 编辑:程序博客网 时间:2024/06/05 15:32

BaseExpandableListAdapter主要用于类似于qq分组这样的显示的适配器

BaseExpandableListAdapteview适用于类似qq分组的模式


//关键代码是这个可扩展的listview适配器class ExAdapter extends BaseExpandableListAdapter {Context context;public ExAdapter(Context context) {super();this.context = context;}//得到大组成员总数public int getGroupCount() {// TODO Auto-generated method stubreturn groupData.size();}//得到小组成员总数public int getChildrenCount(int groupPosition) {// TODO Auto-generated method stubreturn childData.get(groupPosition).size();}//得到大组成员名称public Object getGroup(int groupPosition) {// TODO Auto-generated method stubreturn groupData.get(groupPosition).get(GROUP_TEXT).toString();}//得到小组成员名称public Object getChild(int groupPosition, int childPosition) {// TODO Auto-generated method stubreturn childData.get(groupPosition).get(childPosition).get(CHILD_NAME).toString();}//得到大组成员的idpublic long getGroupId(int groupPosition) {// TODO Auto-generated method stubreturn groupPosition;}//得到小组成员的idpublic long getChildId(int groupPosition, int childPosition) {// TODO Auto-generated method stubreturn childPosition;} /**         * Indicates whether the child and group IDs are stable across changes         * to the underlying data. 表明大組和小组id是否稳定的更改底层数据。         *          * @return whether or not the same ID always refers to the same object         * @see Adapter#hasStableIds()         */public boolean hasStableIds() {// TODO Auto-generated method stubreturn true;}//得到大组成员的viewpublic View getGroupView(int groupPosition, boolean isExpanded,View convertView, ViewGroup parent) {// TODO Auto-generated method stubView view = convertView;if(view == null) {LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);view = inflater.inflate(R.layout.member_listview2, null);}TextView title = (TextView)view.findViewById(R.id.content_001);title.setText(getGroup(groupPosition).toString()); //设置最大组成员名称ImageView image = (ImageView)view.findViewById(R.id.tubiao);  //是否展开大组的图标if(isExpanded) //大组展开时image.setBackgroundResource(R.drawable.hero);elseimage.setBackgroundResource(R.drawable.ic_launcher);return view;}//得到小组成员的viewpublic View getChildView(int groupPosition, int childPosition,boolean isLastChild, View convertView, ViewGroup parent) {// TODO Auto-generated method stubView view = convertView;if(view == null) {LayoutInflater inflater = LayoutInflater.from(context);view = inflater.inflate(R.layout.member_childitem2, null);}final TextView title = (TextView)view.findViewById(R.id.child_name);title.setText(childData.get(groupPosition).get(childPosition).get(CHILD_NAME).toString());  //大标题final TextView title2 = (TextView)view.findViewById(R.id.child_text);title2.setText(childData.get(groupPosition).get(childPosition).get(CHILD_TEXT).toString());  //小标题return view;}//得到小组成员是否被选择public boolean isChildSelectable(int groupPosition, int childPosition) {// TODO Auto-generated method stubreturn true;}}


0 0