开发者

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 that involves progressing through various short "levels", and the whole thing is timed, the objective being to get the fastest time possible. I put levels in quotations because they are very short, and mainly involve doing a few simple tasks (i.e. clicking a button) before progressing to the next one. As a result instead of creating a different activity for each level, I decided to keep everything within one activity and when a user completes all of the tasks for one level, a different layout is 开发者_如何学Cset-up using the setContentView() method. My problem is that every time I switch layouts, I need to reset my pointers to the buttons using findViewById() even though they are named the same. If someone could explain why I need to do this that would be very helpful? Also, as I am fairly new to android, perhaps I am not going about this in the most efficient way? Any suggestions would be welcome and appreciated.

Also I think this is probably related, but I have a chronometer that I want to be persistent across the layouts? I have seen in other questions that this is not possible across activities, but I wanted to check on the case of across layouts.

Thank you in advance for your help.

Edit: Thank you ania, viewflipper looks like the perfect solution

Edit: So after some experimenting with the ViewFlipper I have decided to use it for my project. While it does not solve the issue of having to re-add the buttons with every new level(this I solved by giving each button a distinct name, even across all layouts), it did give me some nice animation effects as well as the convenience of using showNext and showPrevious methods.


Did you try ViewFlipper? It seems like perfect solution in this case.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜