Take a look at the Android Documentation :
Set the activity contents to an explicit view. This view is placed directly in the hierarchy of activities.
So, setContentView overwrite the layout and replace it with a new one. Usually you want to do this only once in onCreate. Theoretically, you could do this more, but it requires re-drawing the entire layout, and this may take some time. There are several alternatives, depending on what you want:
- ViewAnimator : This is useful for showing quick animations if you want to quickly change views several times in a row.
- Fragments - Instead of re-drawing the entire view, you can turn off fragments. Each fragment is a kind of mini-activity, and in general it will contain code much better.
- Pass Intent Arguments - Transfer information to an action that will help him set up. The first action transfers information to a common second activity, which knows how to configure itself based on the information that it receives from the first action.
As for your specific application, here is what I will do:
- Each group follows a specific pattern. There are only 1, or possibly several possible layouts.
- When the action of the group begins, the corresponding layout is selected and filled, knowing what is there.
The Android SDK shows how to transfer data from one activity to another. Just pass the data that is required for the second action from the first, using something like this:
Intent intent=new Intent(...); intent.putExtra("Album","Some Album") startActivity(intent);
The second action will do the following:
Intent intent=getIntent(); String albumName=intent.getExtraString("Album");
PearsonArtPhoto
source share