我在因特网中找到了此代码,这是ExpandableListView
的一个示例。它运行完美。在布局中添加ExpandableListView
import android.app.ExpandableListActivity;
import android.os.Bundle;
import android.widget.ExpandableListAdapter;
import android.widget.SimpleExpandableListAdapter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Demonstrates expandable lists backed by a Simple Map-based adapter
*/
public class SmplExpandableTest extends ExpandableListActivity {
private static final String PARENT_KEY = "pKey";
private static final String CHILD_KEY = "cKey";
private ExpandableListAdapter mAdapter;
@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>>>();
Map<String, String> curGroupMap = new HashMap<String, String>();
groupData.add(curGroupMap);
curGroupMap.put(PARENT_KEY, "Hello");
curGroupMap.put(CHILD_KEY, "First Order System Response");
List<Map<String, String>> children = new ArrayList<Map<String, String>>();
Map<String, String> curChildMap = new HashMap<String, String>();
children.add(curChildMap);
curChildMap.put(PARENT_KEY, "World");
curChildMap.put(CHILD_KEY, "Second Order System");
childData.add(children);
// Set up our adapter
mAdapter = new SimpleExpandableListAdapter(this, groupData,
android.R.layout.simple_expandable_list_item_1, new String[] {
PARENT_KEY, CHILD_KEY }, new int[] {
android.R.id.text1, android.R.id.text2 }, childData,
android.R.layout.simple_expandable_list_item_2, new String[] {
PARENT_KEY, CHILD_KEY }, new int[] {
android.R.id.text1, android.R.id.text2 });
setListAdapter(mAdapter);
}
}
现在我想插入这个ExpandableListView
布局里面,这样我就可以在底部添加一个按钮。我怎样才能做到这一点 ?
感谢
那是一个不少。你能否告诉我,当你在SmplExpandableTest类中添加行时会发生什么? – fean
您应该查看它的文档。 'setContentView'设置布局('ExpandableListActivity'内部使用一些预定义的布局)。然后,您必须将适配器设置为'ExpandableListView'(您不能使用'ExpandableListActivity'的'setListAdapter'实用程序功能)。 – Tomik