I'm pretty new to Android so I apologize if this question sounds stupid in any way.
I'm trying to开发者_运维百科 create an attendance application with many classes but the 2 main ones will be Student and Courses.
I plan to use tabs to navigate with Student and Courses being the 2 tabs in my TabHost.
The Course page for example will list all of the courses currently in the system with an options menu for Adding a course which will bring up an Add Course screen (within the Course tab but changing the view).
So, to my question...
I plan to set an onclick for the options menu item which will call setContentView to display the add new course layout instead of starting a new Activity showing a new layout.
Does this sound like a sensible way to do this? If not what would be a better approach?
All my course logic will be contained within the Course class and so I want all of my code to be contained within there without having to create a class/activity for a course list, adding a course, viewing a course etc.
I hope this makes sense.
Does this sound like a sensible way to do this? If not what would be a better approach?
No, it's not a sensible way to do so. You should open the new activity; that's the Android way. Maybe you are trying to imitate the iPhone tabs style which don't open new windows or something.
If you still want to do so, you better use ActivityGroup
(there are tutorials out there), which IMHO is a pain the ass to use.
It is certainly not a sensible way to do stuffs.
You can however use a ViewFlipper by which you can change the screen layouts. This way you can stay in the same class and change your screen design.
http://developer.android.com/reference/android/widget/ViewFlipper.html
精彩评论