views:

333

answers:

2

Hi all, i am writing a software that i have to drill down on content a lot. For example when the program starts a listview is displayed. When user clicks on an item, then a second listview must be displayed. For example:

Select Continent > Select Country > Select State > Select City > Select Address

  1. What is the best way to do this (less memory, faster, easier to code etc)? To create multiple listviews with multiple adapters? Or 1 listview with multiple Adapters? Lists are loaded from an external XML File.

  2. So far i am creating a new adapter and setting it to the listview. How do i create a second listview and after clicking on 1st listview displaying the second one, with animation. Any examples?

  3. Extend my class to ListActivity or Activity?

Best regards and thanks for helping, Nicos

A: 

I would make multiple Activities for this. The first activity to display Continent list, the second the Country list, Third State list, etc...

When the user than click the back button. It will go back to the previous activity (list). Even the scrollstate would be remembered.

This will also add the OS animation between the activities. The code will also be separated and memory freed when closing the list activity.

Sending a value from one activity to another ex CountryCode tot the StateListActivty is done by setting a intent.putExtra("CountryCode", countryCode);

A second approach would be to use a ViewFlipper. Adding each listview as a child. And than setting a custom animation on the show-next and show-previous actions.

Note: Using multiple activities may use abit more memory than the ViewFlipper approach.

PHP_Jedi
"Note: Using multiple activities may use abit more memory than the ViewFlipper approach." Yes and no. The `ViewFlipper` approach results in one fat activity. Multiple activities will collectively take up more memory, but will individually be slimmer. Since Android's memory management involves destroying activities to free up memory, IMHO, you are better served using multiple activities.
CommonsWare
Agree, I would have used multiple activities, as stated as my first sentance.
PHP_Jedi
A: 

I would use separate activities for each list but with only one List Adapter class to be shared by all so you can retain consistency in terms of how the lists look + easy to maintain code. You can use a bundle to pass info from one activity to another.

Another thought: is the info you are referring to part of "settings" info? By that, I mean, is it info the user would put in once into your app, or would they put it in almost everytime they use the app (because each time the info would be different)? If it's an "one-off" type of info, you would be better off using a PreferenceActivity.

FreewheelNat
Actually the user will select each time the use the app.
Nicos