• ExpandableListView


     //创建一个BaseExpandableListAdapter对象
    ExpandableListAdapter adapter = new BaseExpandableListAdapter()
    {

    public Object getChild(int groupPosition, int childPosition)
    {
    return arms[groupPosition][childPosition];
    }

    @Override
    public long getChildId(int groupPosition, int childPosition)
    {
    return childPosition;
    }

    @Override
    public int getChildrenCount(int groupPosition)
    {
    return arms[groupPosition].length;
    }

    private TextView getTextView()
    {
    AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
    ViewGroup.LayoutParams.MATCH_PARENT, 64);
    TextView textView = new TextView(MainActivity.this);
    textView.setLayoutParams(lp);
    textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
    textView.setPadding(36, 0, 0, 0);
    textView.setTextSize(20);
    return textView;
    }


    // 该方法决定每个子选项的外观
    @Override
    public View getChildView(int groupPosition, int childPosition,
    boolean isLastChild, View convertView, ViewGroup parent)
    {
    TextView textView = getTextView();
    textView.setText(getChild(groupPosition, childPosition)
    .toString());
    return textView;
    }


    // 获取指定组位置处的组数据
    @Override
    public Object getGroup(int groupPosition)
    {
    return armTypes[groupPosition];//设置显示数据1
    }
    @Override
    public int getGroupCount()
    {
    return armTypes.length;//设置组长度
    }
    @Override
    public long getGroupId(int groupPosition)
    {
    return groupPosition;//设置组位置
    }


    /*******************************设置可改*****************************************/
    // 该方法决定每个组选项的外观
    @Override
    public View getGroupView(int groupPosition, boolean isExpanded,
    View convertView, ViewGroup parent)
    {
    LinearLayout ll = new LinearLayout(MainActivity.this);
    ll.setOrientation(0);
    ImageView logo = new ImageView(MainActivity.this);
    logo.setImageResource(logos[groupPosition]);
    ll.addView(logo);
    TextView textView = getTextView();
    textView.setText(getGroup(groupPosition).toString());
    ll.addView(textView);
    return ll;
    }
    /*************************************8*************************************************/

    @Override
    public boolean isChildSelectable(int groupPosition,
    int childPosition)
    {
    return true;
    }
    @Override
    public boolean hasStableIds()
    {
    return true;
    }
    };
    ExpandableListView expandListView = (ExpandableListView) findViewById(R.id.list);
    expandListView.setAdapter(adapter);
    }


  • 相关阅读:
    HAVING用法详解
    spring的定时任务
    js 将json字符串转换为json对象的方法解析
    Struts2 SSH整合框架返回json时,要注意懒加载问题
    Struts2 本是非单例的,与Spring集成就默认为单例
    Android 判断当前联网的类型 wifi、移动数据流量
    Android 动画的重复播放
    Android 监测手机联网状态 wifi、移动数据流量、无联网状态
    Android 设置界面的圆角选项
    Android 用Activity的onTouchEvent来监听滑动手势
  • 原文地址:https://www.cnblogs.com/yhc04161120/p/4816805.html
Copyright © 2020-2023  润新知