My current application has one Activity, the main one which extends ListActivity (listview of course). The main Activity also holds most of the app functions.
I want to add an option for the user to select between 2 views: the current listView and a gridView. I also want to r开发者_Go百科euse my code - most functions can be used for both Views.
Before I ask the actual question, note that my question is NOT how to add a gridView - it's already added and works great (when commenting out all Listview lines).
My question is - how should I do it?
2 different Views means I have to have 2 different Activities? one extends "ListActivity" and one extends "Activity"?
Should I create 4 classes (3 Activities and functions class in this case) where the main Activity will call one of the other Activities according to what the user selected?
Is there a way using the same main Activity for both Views? (right now I extend "ListActivity" to get "getListView()" which causes the gridView to force close as the Activity looks for a ListView with the ID "list").
Any other way?
Thank you!
You can use ListView without using a ListActivity. I would recommend this approach if the rest of your Activity's code will be similiar for both the List and Grid forms. Choose dynamically which one you show and tailor your adapter definitions to do both based on a switch or if statement where needed, rather than using different Activities.
精彩评论