As for your first screen , it depends on the activity and is executed directly when the project starts. For example, if you have a project called FooFoo , then when compiling / creating your android project, the android itself calls the first class as FooFooActivity (i.e. if you allowed the android to create activity from it). Of course, you can rename it then and there yourself. So, as soon as you compile your user interface in the default main.xml file and return to your java FooFooActivity file, there is a specific line inside the onCreate method. This line is setContentView(R.layout.main); This line sets the view. the contents inside this main.xml file. When you run the program and run the emulator, the emulator presents a representation of your main.xml if your project does not contain compilation errors or main.xml .
Now, having come to your 20+ layouts : you can use them in your layout folder. Assign at least one button on each screen, which will take you to some screen, say โXYZโ, and suppose the class name is โABCโ. Suppose also that your FooFooActivity class leads you to this ABC class. In the next steps you will learn how to make a navigation part.
I. Inside the onCreate method of your onCreate class, you already have setContentView . Now, after this line, add the following lines:
Button button = (Button)findViewById(R.id.button1); button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent intent = new Intent(FooFooActivity.this, ABC.class); startActivity(intent); } });
In By transmitting an intention, you can direct yourself / your user to the desired screen / activity.
II. Keep in mind that your ABC class means the same onCreate method and place your XYZ layout inside setContentView as follows: setContentView(R.layout.XYZ);
III. In your manifest file after
<activity android:label="@string/app_name" android:name=".FooFooActivity" > <intent-filter > <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
add the following:
<activity android:name=".ABC" android:label="@string/app_name" > </activity>
Once you are done with these steps, run your program.
Please note that this is just showing 2 screens for your user. You need to repeat it 20 more times. I do not know / do not see another way.
As for your layouts, I would advise you to stick with Relative layout or Linear layout . Generally, most โnormalโ layouts can be achieved with any of these or combinations thereof. If you want more, you can always find help on the Android Developers Site or Stack Overflow . In any case, there are many other things that I could not explain here, but I intend in due time. You can always refer to great books such as Hello Android , Android Programming, and Learning Android . Even CommonsWare - Mark Murphy has its own set of books, which are quite popular. You can always start with any of them.
Hope this helps. All the best!
EDIT YOUR UPDATE:
Of course, it will return the last action, because I assume that you have the following code snippet with an exit button:
Button exit = (Button)findViewById(R.id.button2); exit.setOnClickListener(new OnClickListener() { public void onClick(View v) { finish(); } });
So basically what you do ends up with that particular ABC / Main Activity. This means that android will lead you to the previous screen / activity. All this. If you stick to the same layout and plan to use it for different activities, everything will just be confusing. Only 2 screens / actions, this is pretty confusing for you. Imagine what can happen with 20+. Well, the design is ultimately left to you. That's all I can say.