is using setContentView multiple times bad while changing layouts?
Some people say that it's bad and they never say why.
and is there some other thing to change layout using button?
Let's take a look at the Android Documents:
Set the activity content to an explicit view. This view is placed directly into the activity's view hierarchy.
So, setContentView
will overwrite the layout, and replace it with a new one. Usually, you only want to do this once in onCreate. Theoretically, you could do it more, but it involves re-drawing the entire layout, and this could take some time. There are a few alternatives, depending on exactly what you want:
As for your specific application, here's what I would do:
The Android SDK shows how to pass data from one activity to another. Just pass the data that the second activity needs from the first, using something like this:
Intent intent=new Intent(...);
intent.putExtra("Album","Some Album")
startActivity(intent);
The second activity will do this:
Intent intent=getIntent();
String albumName=intent.getExtraString("Album");
//Does something with albumName, maybe get a TextView and .setText()