zoukankan      html  css  js  c++  java
  • ExpandableList

    一、ExpandableList

    Activity代码:

    public class ExpandableListActivityDemoActivity extends ExpandableListActivity {

        /** Called when the activity is first created. */

        @Override

        public void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);

            setContentView(R.layout.main);

            //声明第一个list对象

            List<Map<String,String>> groups=new ArrayList<Map<String,String>>();

            Map<String,String> map1=new HashMap<String,String>();

            map1.put("group", "中国");

            groups.add(map1);

            Map<String,String> map2=new HashMap<String,String>();

            map2.put("group", "日本");

            groups.add(map2);

           

          //为第一个一级条目提供二级条目的数据

            List<Map<String,String>> child1=new ArrayList<Map<String,String>>();

            Map<String,String> child1data=new HashMap<String,String>();

            child1data.put("child", "香港");

            child1.add(child1data);

            Map<String,String> child2data=new HashMap<String,String>();

            child2data.put("child", "甘肃");

            child1.add(child2data);

           

          //为第二个一级条目提供二级条目的数据

            List<Map<String,String>> child2=new ArrayList<Map<String,String>>();

            Map<String,String> child22data=new HashMap<String,String>();

            child22data.put("child", "北海道");

            child2.add(child22data);

            Map<String,String> child21data=new HashMap<String,String>();

            child21data.put("child", "北海道");

            child2.add(child21data);

           

            List<List<Map<String,String>>> childs=new ArrayList<List<Map<String,String>>>();

            childs.add(child1);

            childs.add(child2);

           

           

            SimpleExpandableListAdapter ada=new SimpleExpandableListAdapter(

                          this,

                          groups, R.layout.groups, new String[]{"group"}, new int[]{R.id.groups},

                          childs,R.layout.child,new String[]{"child"},new int[]{R.id.child}

                          );

            setListAdapter(ada);        

        }

           @Override

           public boolean onChildClick(ExpandableListView parent, View v,

                         int groupPosition, int childPosition, long id) {

                  // TODO Auto-generated method stub

                  Toast.makeText(this, groupPosition+"|"+childPosition, Toast.LENGTH_LONG).show();

                  return super.onChildClick(parent, v, groupPosition, childPosition, id);

           }

       

    }

    groups.xml代码:

    <?xmlversion="1.0"encoding="utf-8"?>

    <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"

        android:orientation="vertical"

        android:layout_width="fill_parent"

        android:layout_height="fill_parent"

        >

    <TextView 

        android:id="@+id/groups" 

        android:layout_width="fill_parent" 

        android:layout_height="wrap_content" 

        android:text="No Data"

        android:padding="15px"

        android:layout_marginLeft="35px"

        />

    </LinearLayout>

    child.xml代码:

    <?xmlversion="1.0"encoding="utf-8"?>

    <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"

        android:orientation="vertical"

        android:layout_width="fill_parent"

        android:layout_height="fill_parent"

        >

    <TextView 

        android:id="@+id/child" 

        android:layout_width="fill_parent" 

        android:layout_height="wrap_content" 

        android:text="No Data"

        android:padding="10px"

        />

    </LinearLayout>

    main.xml代码:

    <?xmlversion="1.0"encoding="utf-8"?>

    <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"

        android:orientation="vertical"

        android:layout_width="fill_parent"

        android:layout_height="fill_parent"

        android:paddingLeft="8dp"

        android:paddingRight="8dp"

        >

    <ExpandableListViewandroid:id="@id/android:list"

        android:orientation="vertical"

        android:layout_width="fill_parent"

        android:layout_height="fill_parent"    

        />

    </LinearLayout>

  • 相关阅读:
    51nod 1087 1 10 100 1000(找规律+递推+stl)
    51nod 1082 与7无关的数 (打表预处理)
    51 nod 1080 两个数的平方和
    1015 水仙花数(水题)
    51 nod 1003 阶乘后面0的数量
    51nod 1002 数塔取数问题
    51 nod 1001 数组中和等于K的数对
    51 nod 1081 子段求和
    51nod 1134 最长递增子序列 (O(nlogn)算法)
    51nod 1174 区间中最大的数(RMQ)
  • 原文地址:https://www.cnblogs.com/itfenqing/p/4429515.html
Copyright © 2011-2022 走看看