SimpleExpandableListAdapter(分组List)参数详解
2014-05-13 23:02
387 查看
SimpleExpandableListAdapter(分组List)注意事项
import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import android.app.ExpandableListActivity; import android.os.Bundle; import android.widget.SimpleExpandableListAdapter; /* * 创建一个Activity,继承ExpandableListAcitivty */ public class MainActivity extends ExpandableListActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //定义一个List,该List对象为一级条目提供数据 List<Map<String, String>> groups = new ArrayList<Map<String, String>>(); Map<String, String> group1 = new HashMap<String, String>(); group1.put("group", "group1"); Map<String, String> group2 = new HashMap<String, String>(); group2.put("group", "group2"); groups.add(group1); groups.add(group2); //定义一个List,该List对象为第一个一级条目提供二级条目的数据 List<Map<String, String>> child1 = new ArrayList<Map<String, String>>(); Map<String, String> child1Data1 = new HashMap<String, String>(); child1Data1.put("child", "child1Data1"); child1.add(child1Data1); Map<String,String> child1Data2 = new HashMap<String,String>(); child1Data2.put("child", "child1Data2"); child1.add(child1Data2); //定义一个List,该List对象为第二个一级条目提供二级条目的数据 List<Map<String, String>> child2 = new ArrayList<Map<String, String>>(); Map<String, String> child2Data = new HashMap<String, String>(); child2Data.put("child", "child2Data"); child2.add(child2Data); //定义一个List,该List对象用来存储所有的二级条目的数据 //数据分组的依据是childs.add()的添加顺序。 //如将49、50行交换顺序,则第一组显示child2,第二组显示child1。 List<List<Map<String, String>>> childs = new ArrayList<List<Map<String, String>>>(); childs.add(child1); childs.add(child2); //生成一个SimpleExpandableListAdapter对象 //1.context //2.一级条目的数据 //3.用来设置一级条目样式的布局文件 //4.指定一级条目数据的key //5.指定一级条目数据显示控件的id //6.指定二级条目的数据 //7.用来设置二级条目样式的布局文件 //8.指定二级条目数据的key //9.指定二级条目数据显示控件的id SimpleExpandableListAdapter sela = new SimpleExpandableListAdapter( this, groups, R.layout.group, new String[] { "group" }, new int[] { R.id.groupTo }, childs, R.layout.child, new String[] { "child" }, new int[] { R.id.childTo }); //将SimpleExpandableListAdapter对象设置给当前的ExpandableListActivity setListAdapter(sela); } }
相关文章推荐
- ExpandableListActivity的学习心得,以及SimpleExandableListAdapter的9个参数介绍
- 了解SimpleExpandableListAdapter的构造函数
- SimpleExpandableListAdapter
- 模拟QQ分组(具有伸缩功能) (添加开源框架的光闪烁效果)SimpleExpandableListAdapter 适配器的用法,并且可添加组及其组内数据。
- Android学习笔记(十八)——ExpandableListActivity与SimpleExpandableListAdapter
- Android中文API(95)——SimpleExpandableListAdapter
- Android 中 ListAactivity 和Activity 使用ListView 以及ArrayAdapter和SimpleAdapter参数详解
- Android中文API(95)——SimpleExpandableListAdapter
- List控件使用---SimpleAdapter使用详解(一)
- ExpandableListView如何进行二级扩展(SimpleExpandableListAdapter)
- List控件使用---SimpleAdapter使用详解(二)
- android学习--ExpandableListActivity和SimpleExpandableListAdapter的使用
- 利用SimpleExpandableListAdapter为ExpandableListActivity提供数据
- List控件使用---SimpleAdapter使用详解(一)
- Android适配器之-----SimpleExpandableListAdapter
- ExpandableListActivity的基本使用方法 ,SimpleExpandableListAdapter的基本使用方法
- Android开发视频第二季之三:ExpandableListActivity和SimpleExpandableListAdapter的使用
- List控件使用---SimpleAdapter使用详解(二)
- Android7.0中文文档(API)-- SimpleExpandableListAdapter
- List控件使用---SimpleAdapter使用详解(一)