如何应该是组织了SimpleExpandableListAdapter数据 [英] How should be the data for a SimpleExpandableListAdapter organized
问题描述
我想创建一个 ExpandableListView
与 SimpleExpandableListAdapter
(我知道我可以扩展新的适配器自己,但我想尝试simpleExapndableListAdapter)。
I am trying to create a ExpandableListView
with the SimpleExpandableListAdapter
(I know I can extend a new adapter myself, but I want to try the simpleExapndableListAdapter).
现在我遇到问题时,我尝试创建一个新的实例 SimpleExpandableListAdapter
。
Now I meet problems when I try to create a new instance of SimpleExpandableListAdapter
.
事件我读<一href="http://developer.android.com/reference/android/widget/SimpleExpandableListAdapter.html#SimpleExpandableListAdapter%28android.content.Context,%20java.util.List%3C?%20extends%20java.util.Map%3Cjava.lang.String,%20?%3E%3E,%20int,%20java.lang.String%5B%5D,%20int%5B%5D,%20java.util.List%3C?%20extends%20java.util.List%3C?%20extends%20java.util.Map%3Cjava.lang.String,%20?%3E%3E%3E,%20int,%20java.lang.String%5B%5D,%20int%5B%5D%29">references,我不是很确定什么是参数的含义尤其是 groupData code>和
childData code>。
Event I read the references, I am not exactly sure what does the parameters mean especially the groupData
and the childData
.
虽然我知道我要创建地图
列表和清单地图列表
,但什么数据应放在那里?如何组织他们?
Though I know I have to create a list of Map
and a list of list of Map
, but what data should be put there? How to organized them?
例如,这是我要显示的数据,如何组织他们?
For example, this is the data I want to display, how to organize them?
++Development Team
John
Bill
++Data Process Team
Alice
David
顺便说一句,这是否意味着我要创建两个布局组和子视图?
BTW, does it mean that I have to create two layout for the group and the child view?
我用Google搜索,并一次又一次地阅读教程,但我无法理解。
I have googled and read the tutorial again and again, but I can not understand it.
我希望有人可以给马一个解释。
I hope someone can give ma an explain.
推荐答案
下面是你想要的,它会清除所有的疑虑简单的示例。
Here is simple sample you wanted, it will clear all your doubts..
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.ExpandableListAdapter;
import android.widget.SimpleExpandableListAdapter;
public class SimpleExpandableListExampleActivity extends ExpandableListActivity {
private static final String NAME = "NAME";
private ExpandableListAdapter mAdapter;
private String group[] = {"Development" , "Data Process Team"};
private String[][] child = { { "John", "Bill" }, { "Alice", "David" } };
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>();
for (int i = 0; i < group.length; i++) {
Map<String, String> curGroupMap = new HashMap<String, String>();
groupData.add(curGroupMap);
curGroupMap.put(NAME, group[i]);
List<Map<String, String>> children = new ArrayList<Map<String, String>>();
for (int j = 0; j < child[i].length; j++) {
Map<String, String> curChildMap = new HashMap<String, String>();
children.add(curChildMap);
curChildMap.put(NAME, child[i][j]);
}
childData.add(children);
}
// Set up our adapter
mAdapter = new SimpleExpandableListAdapter(this, groupData,
android.R.layout.simple_expandable_list_item_1,
new String[] { NAME }, new int[] { android.R.id.text1 },
childData, android.R.layout.simple_expandable_list_item_2,
new String[] { NAME }, new int[] { android.R.id.text1 });
setListAdapter(mAdapter);
}
}
所有你需要做的就是
All you have to do is
- 创建与
SimpleExpandableListExampleActivity
作为Android项目 您的主要活动。 - 复制 - 粘贴在该活动中给出的code。
- 在那呢..运行您的code ...
- Create an Android project with
SimpleExpandableListExampleActivity
as your main activity.. - Copy-paste the code given in that activity.
- Thats it.. Run your code...
希望这有助于...
这篇关于如何应该是组织了SimpleExpandableListAdapter数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!