Reputation: 3453
I have a quiz app with many categories:
Category 1
Category 3
Category 4
Category 5
So category either refers to a general non selectable category which is the category heading or an actual category. So for example within let's say that category 1 is fruits, there could be questions on apples and bananas. Apples and bananas would be selectable and also show how many questions were in category. But then category 3 would be vegetables which itself is selectable holding for example 100 questions.
Now is there the possibility of making this into an expandablelistview for each category. However categories that don't have additional questions are non expandable. Is there the possibility of putting buttons within the expandable list view or would these have to be separate? What about checkboxes?
Thanks
Upvotes: 1
Views: 183
Reputation: 10622
You can create sectioned list easily by using following library.you can create it in six line
So you can have header for each category in listview
How to Implement this,
// 1. Your data source
String[] books = new String[] {
"A Item", "F Item", "D Item",
"H Item", "T Item",
"A Item 1", "T Item 2"
};
// 2. Sort it
Arrays.sort(books, 0, books.length, Collator.getInstance());
// 3. Create your adapter
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, books);
// 4. Create a Sectionizer
Sectionizer<String> alphabetSectionizer = new Sectionizer<String>() {
@Override
public String getSectionTitleForItem(String categoryName) {
return bookName;
}
};
// 5. Wrap your adapter within the SimpleSectionAdapter
SimpleSectionAdapter<String> sectionAdapter = new SimpleSectionAdapter<String>(this,
adapter, R.layout.section_header, R.id.title, alphabetSectionizer);
// 6. Set the adapter to your ListView
setListAdapter(sectionAdapter);
Upvotes: 2