0

我想在我的 Android 项目中使用 ExpandableListView。

我使用 String.xml-Resources 编辑器创建了一个名为“colors”的字符串数组,其中包含不同的项目。

然后我将“ android.entries="@array/colors " 放到 main.xml 中 ExpandableListView 的布局属性中。

一开始会出现以下错误:"The following classes could not be found", Change to android.widget.ExpandableListView.

所以我将main.xml中的“ ExpandableListView”改为“ android.widget.ExpandableListView”。

但后来我收到以下错误:"The following classes could not be instantiated: android.widget.ExpandableListView (Open Class, Show Error Log).

有关详细信息,请参阅错误日志(窗口 -> 显示视图)。”。

我该如何解决这个问题?有没有关于 Android-ExpandableListView 的好教程?提前致谢。

4

1 回答 1

2

android:entries is not for ExpandableListViews. Check the docs here.

ExpandableListView is to display two levels, and you are only specifying one, no need for an ExpandableListView.

An example where you would use something like this is a grocery list program where there are entries for categories and locations for each item and you want to be able to group your list by one or the other.

You would create a "group" array that would contain the list of things you want to group on (say the category of item in the aforementioned grocery list). Then you would create a "child" array for each of those group names containing the items that belong to that group. Note that the adapter you use usually does this second part (creating the "child" arrays/cursors/whatever your data structure is) for you, it is normal to feed in only the group list and let the adapter handle the rest.

An answer I gave recently with some sample code for creating an ExpandableListView using cursors and a SimpleCursorTreeAdapter is here

于 2012-07-24T12:08:03.510 回答