
Question:
I was wondering how I could show 2 different layouts within one activity. I have a multiplayer game right now that waits for opponenets to be found and what I want to have is to have a loading screen that appears while the oppenent is being found in the background and when the opponent is found the other layout will show up
// Get animal & background selected by user
setContentView(R.layout.activity_pregame_selection_multi);
... ...
// Display the multiplayer screen
setContentView(R.layout.activity_multi_player);
however the first layout doesnt show up. only a blank screen
Answer1:I wouldn't play with the setContentView
, it's too heavy for this simple operation. Just use a the "waiting" view on top of your wanted view, and play with the setVisibilty
Visible/Gone.
If you find yourself in need of 2 setContentView
you probably need 2 activities / fragments
You can also simply use View.Gone and View.visible. just put the loading view on top. use View.visible on the loading view and View.Gone on the root of the other views. than, when the loading or waiting is done simply do View.Gone on the loading view and View.Visible on the rest.