Reputation: 61
I want to use an ExpandableListView in my Android project.
I create a String Array called "colors" with different items with the String.xml-Resources editor.
Then I put "android.entries="@array/colors" to the layout-properties of the ExpandableListView in the main.xml.
At first the following error occurs: "The following classes could not be found", Change to android.widget.ExpandableListView.
So I change "ExpandableListView
" to "android.widget.ExpandableListView
" in the main.xml.
But then I get the following error: "The following classes could not be instantiated: android.widget.ExpandableListView (Open Class, Show Error Log).
See the Error Log (Window -> Show View) for more details.".
How can I solve that problem ? And is there any good tutorial on Android-ExpandableListView ? Thanks in advance.
Upvotes: 0
Views: 1570
Reputation: 16393
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
Upvotes: 2