【发布时间】:2013-07-14 05:16:52
【问题描述】:
我有一个可工作的可扩展列表视图代码,它作为一个独立的工作正常。 我有另一个用于滑动标签视图的工作代码,我单独编写。
这两篇文章都是在阅读了许多博客、android dev 和 stackoverflow 问题后编写的。
当我尝试将可扩展列表视图合并并放入其中一个片段时,我最终遇到了一个错误,我无法解决。
这是片段中的代码:
public class Fragment1 extends Fragment {
private static final String NAME = "NAME";
private static final String IS_EVEN = "IS_EVEN";
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>>>();
for (int i = 0; i < 10; i++) {
Map<String, String> curGroupMap = new HashMap<String, String>();
groupData.add(curGroupMap);
curGroupMap.put(NAME, "Group " + i);
curGroupMap.put(IS_EVEN, (i % 2 == 0) ? "This group is even" : "This group is odd");
List<Map<String, String>> children = new ArrayList<Map<String, String>>();
for (int j = 0; j < 2; j++) {
Map<String, String> curChildMap = new HashMap<String, String>();
children.add(curChildMap);
curChildMap.put(NAME, "Child " + j);
curChildMap.put(IS_EVEN, (j % 2 == 0) ? "This child is even" : "This child is odd");
}
childData.add(children);
}
// Set up our adapter
mAdapter = new SimpleExpandableListAdapter(
getActivity(),
groupData,
android.R.layout.simple_expandable_list_item_1,
new String[] { NAME, IS_EVEN },
new int[] { android.R.id.text1, android.R.id.text2 },
childData,
android.R.layout.simple_expandable_list_item_2,
new String[] { NAME, IS_EVEN },
new int[] { android.R.id.text1, android.R.id.text2 }
);
setListAdapter(mAdapter);
}
}`
最后一行总是报错:'The method setListAdapter(ExpandableListAdapter) is undefined for the type Fragment1'。
其余代码没有显示错误。
请帮忙。我该如何解决这个问题。
【问题讨论】:
-
可能对你有帮助 gist.github.com/mosabua/1316903
-
谢谢.. 我试过这个例子,但是当我在 AVD 上运行它时没有得到任何列表视图,它在片段中给出了一个 blenk 屏幕。
标签: android android-fragments expandablelistview