AJD
AJD

Reputation: 1025

Should I create multiple hidden ListViews or just one and change the contents

So I have an activity that will display a list of options and when you click an option it should move to a list that displays the choices for that option, but I'd like both lists to be in the same activity.

I'm debating between the two options of using a single listview and changing the contents (maybe by swapping the adapter if that works, not sure) whenever a user navigates between the two lists, or using something like a viewswitcher where both lists exist independently, but only one is visible at a time.

I would definitely think the viewswitcher option would be the cleaner option, but how will it perform especially if I need to scale it to more than two lists? Is there much overhead to creating a listview that's not rendered?

Upvotes: 0

Views: 93

Answers (2)

Gomoku7
Gomoku7

Reputation: 1372

I did have a choice like that. I was using a list view to navigate to a remote webdav server. At the beginning I was using one view for each folder. It was cool: using back was allowing me not to worry about navigation history. But after a while, there was some cases where I needed to manage all the views at once, or kill them all or implement a communication between views (for parameters). And it was a nightmare to achieve. Also my list were beginning to be heavy and a lot of list in memory is never a good thing. I finally gave up and managed all the navigation in a unique list view. I should have do it at first.

Upvotes: 0

Alexander Lucas
Alexander Lucas

Reputation: 22371

Keeping one listview and switching out its backend would be a pain, especially considering all the re-initialization every single time you click an option.

-Use two ListFragments, have one control the other. Using Fragments instead of two separate ListActivities would mean that when you build a tablet interface, it would be minimal work to have one Activity with both on the same screen.

-Use an ExpandableListView

Upvotes: 1

Related Questions