Reputation: 3022
When do I need to create a new activity and when do I need to change the view?
My app needs to do:
two big buttons(sort of menu)
list of items - depend on the selection on prev screen
another list - depend on the selection on prev screen
show item
All screens need to have the same menu menu (the last has another button)
Do I need to create an activity for each screen or just change the view in the same activity?
Maybe I need to create a parent class myBase
that will extend activity and all my activities will extend him?
Upvotes: 22
Views: 32810
Reputation: 356
View is Display System of Android where you define layout to put subclasses of View in it eg. Buttons, Images etc. But Activity is Screen System of Android where you put display as well as user-interaction,(or whatever which can be contained in full-screen Window.)
Now for your question,you are creating full window screen#2 ,screen#3... ,so it is activity. In these screen you can define layout/or Views.
I hope it helps.
Upvotes: 2
Reputation: 15573
The "right" way to do it is to use Activity for each screen and use the <include>
tag for the menu you would like to be in all screens.
This way you will have the "back" button act as it should be and it would be easier for you to handle when switching screens.
To use the , you should put the things you want to reuse into extra files. Then you can use it as follows:
<!-- my_header.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/text01"/>
In another file include it with:
<include layout="@layout/my_header" />
<!-- your other stuff -->
Upvotes: 10
Reputation: 2660
A View in Android is a widget that displays something. Buttons, listviews, imageviews, etc. are all subclasses of View. When you say "change view" I assume you mean change the layout by using setContentView(). This usually only needs to be done once per activity. An Activity is basically what you are referring to as a screen. To answer your question, it sounds like you need four separate activities (one for each screen).
Upvotes: 18
Reputation: 13501
You should create 4 xml files... and play Around changing content using setContentView(R.Layout.yourxml);..
you can do this using single Activity.. it depends on how big the class becomes.. if its too heavy with lot of different stuff, for the sake of cohision
and to avoid coupling
use multiple Activities
Upvotes: 1
Reputation: 1726
You should create separate activities for you screens. Android handles the back button of the device by popping the current activity out from the stack and displaying the last one. So if for example the user wants to return to screen 2 for another selection, the back button does this.
Upvotes: 17
Reputation: 24031
activity is like canvas where you put your drawing as view.Yes you can set all above four view in single activity but it will depend how you handle it and does your app needs it to be done like this.
Upvotes: 3