zoukankan      html  css  js  c++  java
  • expandablelistview 的用法

    package com.example.getshareperference;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.BaseExpandableListAdapter;
    import android.widget.ExpandableListView;
    import android.widget.TextView;
    
    public class MainActivity extends Activity {
        private ExpandableListView listview;
        private MyAdapter myAdapter;
        private List<String> group;
        private List<List<String>> child;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            initData();
            listview = (ExpandableListView) findViewById(R.id.expandableListView1);
            myAdapter = new MyAdapter();
            listview.setAdapter(myAdapter);
            listview.setGroupIndicator(null);
        }
    
        public void initData() {
            group = new ArrayList<String>();
            child = new ArrayList<List<String>>();
            addInfo("湖北省", new String[] { "武汉市", "黄石市", "荆州市", "随州市", "宜昌市" });
            addInfo("湖南省", new String[] { "长沙市", "株洲市", "湘潭市", "衡阳市", "邵阳市" });
            addInfo("广东省", new String[] { "广州市", "深圳市", "珠海市", "汕头市", "佛山市" });
            addInfo("广西省", new String[] { "南宁市", "柳州市", "桂林市", "梧州市", "北海市" });
            
        }
    
        public void addInfo(String g, String[] c) {
            group.add(g);
            List<String> list = new ArrayList<String>();
            for (int i = 0; i < c.length; i++) {
                list.add(c[i]);
            }
            child.add(list);
        }
    
        class MyAdapter extends BaseExpandableListAdapter {
    
            @Override
            public int getGroupCount() {
                // TODO Auto-generated method stub
                return group.size();
            }
    
            @Override
            public int getChildrenCount(int groupPosition) {
                // TODO Auto-generated method stub
                return child.size();
            }
    
            @Override
            public Object getGroup(int groupPosition) {
                // TODO Auto-generated method stub
                return group.get(groupPosition);
            }
    
            @Override
            public Object getChild(int groupPosition, int childPosition) {
                // TODO Auto-generated method stub
                return child.get(groupPosition).get(childPosition);
            }
    
            @Override
            public long getGroupId(int groupPosition) {
                // TODO Auto-generated method stub
                return groupPosition;
            }
    
            @Override
            public long getChildId(int groupPosition, int childPosition) {
                // TODO Auto-generated method stub
                return childPosition;
            }
    
            @Override
            public boolean hasStableIds() {
                // TODO Auto-generated method stub
                return false;
            }
    
            @Override
            public View getGroupView(int groupPosition, boolean isExpanded,
                    View convertView, ViewGroup parent) {
                // TODO Auto-generated method stub
                TextView textView = null;
                if (convertView == null) {
                    textView = new TextView(MainActivity.this);
                }
                else{
                    textView=(TextView)convertView;
                }
                textView.setText(group.get(groupPosition));
                textView.setTextSize(30);
                textView.setPadding(32,10, 10, 20);
                return textView;
            }
    
            @Override
            public View getChildView(int groupPosition, int childPosition,
                    boolean isLastChild, View convertView, ViewGroup parent) {
                // TODO Auto-generated method stub
                TextView textView = null;
                if (convertView == null) {
                    textView = new TextView(MainActivity.this);
                }
                else{
                    textView=(TextView)convertView;
                }
                textView.setText(child.get(groupPosition).get(childPosition));
                textView.setTextSize(20);
                textView.setPadding(60, 10, 0, 10);
                return textView;
            }
    
            @Override
            public boolean isChildSelectable(int groupPosition, int childPosition) {
                // TODO Auto-generated method stub
                return true;
            }
    
        }
    }
  • 相关阅读:
    【WIN10】我的第一個WIN10-UWP應用——古文觀止
    【WIN10】文本圖標
    【WIN10】VisualStateManager使用說明
    【WIN10】Storyboard動畫板
    【WIN10】Bind、Binding與Converter的使用
    struts执行过程
    在jsp中的局部和全局变量
    jsp页面中的:<%@ page contentType="text/html; charset=utf-8" language="java"%>的作用及含义
    jsp中的this
    在Java接口中怎样访问定义的常量呢?
  • 原文地址:https://www.cnblogs.com/mf0819/p/3819971.html
Copyright © 2011-2022 走看看