Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Mobile / Android

Multiple Screens Using Google App Inventor

4.33/5 (4 votes)
14 Jan 2011CPOL2 min read 60.3K   3.5K  
Making multiple virtual screens on your App Inventor project

Introduction

Many developers started to play with Google App Inventor to develop simple applications, instead of writing lots of code. But one of the biggest problems encountered is the fact that you can't have multiple screens. So in this tutorial, you are going to learn how to virtualize screens in a very simple, useful and easy way.

Background

Before reading this tutorial, you need to have some experience using the Google App Inventor, if you have finished the HelloPurr you can proceed, but remember that App Inventor Blocks Editor uses Java language, so it will be nice if you already got some knowledge in Java.

The Design Part

As App Inventor is a lot visual, let's start by adding two VerticalArrangement boxes like shown below. One called vScreen1, that will simulate the main screen and the other called vScreen2, that should emulate a secondary screen on your application:

So after you have done that, start putting some objects into both, for a test in this case, I've inserted a lot of stuff on both, and as you can see on the second one, I've inserted other alignment tools (works nice). After all, I got something like this:

Important: You should never forget to do this. On both VerticalArrangement tools, you should put the Width and Height properties as Fill Parent..., as shown below:

Important Step!

As you can see in the image, the values are from the second screen (vScreen2) and its Visible property is false, that's because we don't want it to be shown with the main screen (vScreen1) so when the application starts, it would be hidden.

That's all for the application design part, so let's dive into some code now...

Coding...

Now let's go to the Blocks Editor to have some fun. Start by creating a new function for the button that will take the user for the second screen, on this tutorial, I'm using the function btGo2.Click. After this turn, the vScreen1 invisible, and then turn the vScreen2 visible, so now you the user would be in the second screen. If you want to make it more real, change the title of the Screen1 (the real application screen) to the title that you want for the new screen. Just like this:

btGo2 Code

But now the user is stuck on the second screen, as we added a Back button (btBack) on the second screen, we can change this code a bit to make it go back to the first one:

btBack Code

The full code will look like this:

Full Code

Conclusion

As you can see, it's very simple, but very useful. With this simple snippet, you can do multiple screens virtually. Don't forget that you can do this with infinity screens.

History

  • Original article

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)