call a method in the main Activity. From a Custom View class
i am using the following method in a new application i'm开发者_如何转开发 developing.
there is a main activity, which instantiates different classes that extends RelativeLayout, and i'm using setContentView to switch between the different modules of the application.
i wonder if this is a good approach or necesarily i have to use different activities to the several screens the app haves.
I'd recommend using different activities, then you automatically get navigation between them via the back button. Plus, there will be subtle things that won't work right if you do it the way you're describing -- for example, Android automatically saves the focused control when you switch activities. It won't do this for your content views; you would have to save/restore focus yourself.
Alternatively, if it doesn't make sense for a user to go "back and forth" between the screens of your application, then you could still implement the application with multiple activities, using android.app.TabHost
. This is what the Contact app uses, for example. Then each screen is just a sub-activity, and the whole app is really treated as a single activity. And if you want, you can use TabHost
without actually having tabs. You can hide the tabs and enable navigation via buttons or menu items instead.
精彩评论