zoukankan      html  css  js  c++  java
  • 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);
    }


  • 相关阅读:
    Java中==和equals的区别
    (转)JAVA-反射机制的使用
    JAVA三框架工作原理是什么?
    Spring的IoC模式
    JavaEE中为什么出现中文乱码?
    Android--Apache HttpClient(2种实现)
    Android之网络----使用HttpClient发送HTTP请求(通过get方法获取数据)
    Android—Http连接之GET/POST请求
    2014 12 04
    struts2的HelloWorld的基本过程
  • 原文地址:https://www.cnblogs.com/yhc04161120/p/4816805.html
Copyright © 2011-2022 走看看