• 3月18日学习日志


    今天学习了可折叠列表的使用。

    activity代码为:

    public class MyBaseExpandableListAdapter extends BaseExpandableListAdapter {
    
        private ArrayList<Group> gData;
        private ArrayList<ArrayList<Item>> iData;
        private Context mContext;
    
        public MyBaseExpandableListAdapter(ArrayList<Group> gData,ArrayList<ArrayList<Item>> iData, Context mContext) {
            this.gData = gData;
            this.iData = iData;
            this.mContext = mContext;
        }
    
        @Override
        public int getGroupCount() {
            return gData.size();
        }
    
        @Override
        public int getChildrenCount(int groupPosition) {
            return iData.get(groupPosition).size();
        }
    
        @Override
        public Group getGroup(int groupPosition) {
            return gData.get(groupPosition);
        }
    
        @Override
        public Item getChild(int groupPosition, int childPosition) {
            return iData.get(groupPosition).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 false;
        }
    
        //取得用于显示给定分组的视图. 这个方法仅返回分组的视图对象
        @Override
        public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
    
            ViewHolderGroup groupHolder;
            if(convertView == null){
                convertView = LayoutInflater.from(mContext).inflate(
                        R.layout.item_exlist_group, parent, false);
                groupHolder = new ViewHolderGroup();
                groupHolder.tv_group_name = (TextView) convertView.findViewById(R.id.tv_group_name);
                convertView.setTag(groupHolder);
            }else{
                groupHolder = (ViewHolderGroup) convertView.getTag();
            }
            groupHolder.tv_group_name.setText(gData.get(groupPosition).getgName());
            return convertView;
        }
    
        //取得显示给定分组给定子位置的数据用的视图
        @Override
        public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
            ViewHolderItem itemHolder;
            if(convertView == null){
                convertView = LayoutInflater.from(mContext).inflate(
                        R.layout.item_exlist_item, parent, false);
                itemHolder = new ViewHolderItem();
                itemHolder.img_icon = (ImageView) convertView.findViewById(R.id.img_icon);
                itemHolder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
                convertView.setTag(itemHolder);
            }else{
                itemHolder = (ViewHolderItem) convertView.getTag();
            }
            itemHolder.img_icon.setImageResource(iData.get(groupPosition).get(childPosition).getiId());
            itemHolder.tv_name.setText(iData.get(groupPosition).get(childPosition).getiName());
            return convertView;
        }
    
        //设置子列表是否可选中
        @Override
        public boolean isChildSelectable(int groupPosition, int childPosition) {
            return true;
        }
    
    
        private static class ViewHolderGroup{
            private TextView tv_group_name;
        }
    
        private static class ViewHolderItem{
            private ImageView img_icon;
            private TextView tv_name;
        }
    
    }
  • 相关阅读:
    redis几种数据类型以及使用场景
    Ubuntu16.04安装redis和php的redis扩展
    详细透彻解读Git与SVN的区别(集中式VS分布式)
    bootstrap轮播如何支持移动端滑动手势
    vue添加cnzz统计访问量
    el-tabs值修改时更新路由参数值
    Vue ,elementUI,dropdown组件中command方法添加额外参数的方法
    vue页面滚动监听
    mintui tabbar底部跳转页面
    vue 引入bootstrap
  • 原文地址:https://www.cnblogs.com/20193925zxt/p/14883176.html
Copyright © 2020-2023  润新知