I m试图为我的移动计算班制作简单的RSS馈电读物。 I ve创建了一个管理和维护RSS数据的班子。
@SuppressWarnings("unchecked")
SimpleExpandableListAdapter rssItemList = new SimpleExpandableListAdapter(
this, // context (this class)
createTitleList(), // Creating group List
R.layout.parent_row, // Group item layout XML
new String[]{"titles"}, // the key of group item
new int[]{R.id.itemTitle}, // ID of each group item.-Data under the key goes into this TextView
createChildList(), // childData describes second-level entries
R.layout.child_row, // Layout for sub-level entries(second level)
new String[]{"desc"}, // Keys in childData maps to display
new int[]{R.id.itemDesc} // Data under the keys above go into these TextViews
);
setListAdapter(rssItemList);
我的问题正在显示,我试图使用一种可扩展的List言语,在我试图扩大名单上的一个项目时,我就留下了一个错误。
E/AndroidRuntime( 2542): FATAL EXCEPTION: main
E/AndroidRuntime( 2542): java.lang.ClassCastException: java.util.HashMap
E/AndroidRuntime( 2542): at android.widget.SimpleExpandableListAdapter.getChildrenCount(SimpleExpandableListAdapter.java:255)
E/AndroidRuntime( 2542): at android.widget.ExpandableListConnector.refreshExpGroupMetadataList(ExpandableListConnector.java:561)
E/AndroidRuntime( 2542): at android.widget.ExpandableListConnector.expandGroup(ExpandableListConnector.java:682)
E/AndroidRuntime( 2542): at android.widget.ExpandableListView.handleItemClick(ExpandableListView.java:567)
E/AndroidRuntime( 2542): at android.widget.ExpandableListView.performItemClick(ExpandableListView.java:527)
E/AndroidRuntime( 2542): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696)
E/AndroidRuntime( 2542): at android.os.Handler.handleCallback(Handler.java:587)
E/AndroidRuntime( 2542): at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime( 2542): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 2542): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime( 2542): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 2542): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 2542): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime( 2542): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime( 2542): at dalvik.system.NativeStart.main(Native Method)
我不理解我为什么会发现这一错误,因为我制作团体和儿童名单的法典几乎相同。
@SuppressWarnings({ "unchecked", "rawtypes" })
private List createTitleList(){
ArrayList itemTitles = new ArrayList();
ArrayList<ItemData> entriesList = (ArrayList<ItemData>) feed.getMessages();
for(int i = 0; i < entriesList.size(); i++){
HashMap m = new HashMap();
m.put("titles", entriesList.get(i).getTitle());
itemTitles.add(m);
}
return itemTitles;
}
@SuppressWarnings({ "unchecked", "rawtypes" })
private List createChildList(){
ArrayList itemDesc = new ArrayList(); // item description list
ArrayList<ItemData> entriesList = (ArrayList<ItemData>) feed.getMessages();
for(int i = 0; i < entriesList.size(); i++){
HashMap<String, String> m = new HashMap<String, String>();
m.put("desc", entriesList.get(i).getDescription());
itemDesc.add(m);
}
return (List)itemDesc;
}
很显然,它将展示团体名单,但获得扩大以显示儿童名单。
为帮助未来的神职人员,我正在使用以下辅导: