how to create multiple list view in android

2019-06-03 14:48发布

问题:

How can I create multiple list views within a single activity? Each ListView should have a separated header which allows expanding or collapsing its list, and scrolling on any ListView should scroll the entire activity (NOT one scroll for first ListView and another for second ListView ONLY one scroll for BOTH ListView...)

listviews dynamically fills...

Here's a screenshot of a similar view:

回答1:

What you're describing is an ExpandableListView

The simplest way to create one is by changing your ListView in XML to ExpandableListView and use one of the implementations of ExpandableListAdapter like SimpleExpandableListAdapter or BaseExpandableListAdapter, which work similarly to their non-expandable versions.

Here's an example from the Android samples API which you can download using SDK Manager.