zoukankan      html  css  js  c++  java
  • 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;
        }
    
    }
  • 相关阅读:
    将Python脚本变为命令行--click模块使用
    MongoDB大批量读写数据优化记录
    [转]MongoDB更新操作replaceOne()实例讲解
    pip 18.1: pipenv graph results in ImportError: cannot import name 'get_installed_distributions'
    mitmdump 屏蔽443错误
    python3 操作appium
    appium-Could not obtain screenshot: [object Object]
    scrapy主动触发关闭爬虫
    匿名函数
    装饰器1、无参数的装饰器 2、有参数的装饰器 3、装饰器本身带参数的以及如果函数带return结果的情况
  • 原文地址:https://www.cnblogs.com/20193925zxt/p/14883176.html
Copyright © 2011-2022 走看看