实现分组+固定表头的ListView之PinnedHeaderListView

首相先在gradle里引入PinnedHeaderListView


和普通的listview一样,只不过分组。一个头部一组数据。 如果 你要用直接把下面的代码拷入;

    class ApprovalSectionedAdapter extends SectionedBaseAdapter implements PinnedHeaderListView.PinnedSectionedHeaderAdapter {


        private List<String> headList = new ArrayList<String>();//这里是头部的集合
        private List<List<Communityroom>> approvalMap = new ArrayList();//这里是每个头部下数据的分组的数据结合。注Communityroom是我的一个类;


        public ApprovalSectionedAdapter(List<String> headList, List<List<Communityroom>> approvalMap) {
            this.headList = headList;
            this.approvalMap = approvalMap;
        }


        @Override
        public Object getItem(int section, int position) {//得到每个分组的单个数据(不包含头部)


            return approvalMap.get(section).get(position);
        }


        @Override
        public long getItemId(int section, int position) {
            return position;
        }


        @Override
        public int getSectionCount() {//有多少个头部分组
            Log.e("[ZOZO]", "headList.size()--->" + headList.size());
            return headList.size();


        }


        @Override
        public int getCountForSection(int section) {//头部下总的数据;
            List<Communityroom> contentList = approvalMap.get(section);
            Log.e("[ZOZO]", "contentList.size()--->" + contentList.size());
            return contentList.size();
        }


        @Override
        public View getItemView(final int section, int position, View convertView, ViewGroup parent) {//加载头部下的分组布局
            LinearLayout layout = null;
            if (convertView == null) {
                LayoutInflater inflator = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                layout = (LinearLayout) inflator.inflate(R.layout.attenttionadapter2, null);


            } else {
                layout = (LinearLayout) convertView;
            }
            final Communityroom contentMap = approvalMap.get(section).get(position);
            layout.setTag(contentMap);//这里个listview一样哦。下面是加载我的东西。你可以把你的东西加上。
         /*   final String content = contentMap.present;
            ImageView avatar = (ImageView) layout.findViewById(R.id.avatar);
            TextView name = (TextView) layout.findViewById(R.id.title);
            TextView contentview = (TextView) layout.findViewById(R.id.industry);
            TextView numble = (TextView) layout.findViewById(R.id.number);
            name.setText(contentMap.name);
            numble.setText(contentMap.count + "人");
            contentview.setText(contentMap.present + "fff");
            String uri2 = WebMgr.communityPicPath(contentMap.avatar);


            ImageLoader.getInstance().displayImage(uri2, avatar, ImageLoadTool.optionsAvatarnodefault);
            layout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent il = new Intent(MycommunityActivity.this, L0_CommunityActivity.class);
                    il.putExtra(L0_CommunityActivity.Result_type,1);
                    il.putExtra("gid",contentMap.gid);
                    startActivity(il);
                }
            });*/
            return layout;
        }


        @Override
        public View getSectionHeaderView(int section, View convertView, ViewGroup parent) {//加载头部的布局
            LinearLayout layout = null;
            if (convertView == null) {
                LayoutInflater inflator = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                layout = (LinearLayout) inflator.inflate(R.layout.g0_3_approval_template_section_view, null);
            } else {
                layout = (LinearLayout) convertView;
            }
            layout.setTag(headList.get(section));
            int size = contentMapList.get(section).size();
            String title = headList.get(section);
            ((TextView) layout.findViewById(R.id.textItem)).setText(title + "(" + size + ")");


            return layout;
        }


    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值