Changing / using multiple layouts within the same activity?

I am new to Android programming, but have a pretty strong Java background. I am working on creating a fairly simple game, which includes progress through various short “levels”, and all this is timed, the goal is to get the fastest time. I add levels to quotes because they are very short and basically involve performing a few simple tasks (like clicking a button) before moving on to the next one. As a result, instead of creating different actions for each level, I decided to save everything within one action, and when the user completes all tasks for one level, another layout is configured using the setContentView () method. My problem is that every time I switch layouts, I need to reset my button pointers with findViewById (), although they are named the same. If someone could explain why I need this, would that be very helpful? Also, since I'm pretty new to android, maybe I'm not going to talk about this in the most efficient way? Any suggestions are welcome and appreciated.

I also think that this is probably related, but do I have a chronometer that I want to be consistent in layouts? I saw in other questions that this is not possible in different actions, but I wanted to check the case with the layouts.

Thank you in advance for your help.

Edit: Thanks, ania, viewflipper looks like the perfect solution

Edit: So, after some experimenting with ViewFlipper, I decided to use it for my project. Although this does not solve the problem of re-adding buttons with each new level (I solved this by giving each button a clear name even in all layouts), it gave me nice animation effects, as well as the convenience of using the showNext and showPrevious methods.

+4
source share
1 answer

Have you tried ViewFlipper ? In this case, this is the perfect solution.

+2
source

All Articles