Join Michael Lehman for an in-depth discussion in this video Building a HelloWorld app, part of Learning Simple Android Development Tools.
So lets go ahead a Hello World with basic for android. We'll launch basic for android. Click the close button on the splash dialogue box. We'll come up to the file menu and click save. And we'll call it Helloworld. And then we need to design our user interface just as before. For basic for android we'll click on the designer and this an abstract designer. Later on we'll learn how to be able to see the design. On an Android device, live, while you're actually updating this design. But for right now, we're simply going to come over here, click add view and add a button and add a label.
We'll put the button up here at the top of the screen. We'll put the label, down here in the middle of the screen, make it the width of the screen. We'll come down here and set the text style of the label to be 24 point. We'll make it have it's text alignment to be center. We'll comeback up to our button. We'll change it's text to say tap me, and now that we've done the design, now we have to actually. Tell the designer to put the code for these particular items back into basics for Android on the coding side.
And you do that by going to the tools menu and select generate members. And so we need to do three things. We need to have a definition for button and a definition for label. And we also want a click handler for the button. So we click those three things, button one. Click and label one and click generate members. And then we'll click close. Finally, we need to save our layout here, so that we can use it inside of our basic code. And so we'll come to the file menu of the designer and click save as.
And we'll call it, HelloWorldLayout1. Click okay. Now we can come back to the code window. going to get rid of the default message box that is part of the sample template. And then we're going to uncomment this Activity.LoadLayout, and make sure we put in the right name, HelloWorldLayout1. And now you notice we have definitions for button one and label one. And we have a click handler down here for button one. And in our click handler, we simply want to say Label1.Text = Hello There Android, and now we're ready to run.
So I'm going to go ahead and put the window back over here on the left hand side of the screen. And I've already got the Android emulator running, so I'm just going to bring it up. In the next movie, I'll describe how to get the Android emulator defined and running, but for now, we're simply going to go ahead and click on the run button here. It's going to build a code and it's installing the app onto our virtual device here. And there we go. There's our tap me button, we tap on the tap me button, we see hello there Android. Okay, so that's Helloworld. So, the process which we're going to do over and over in this particular chapter of the course is to create or open up a project, open up the designer.
Create controls on the screen, perhaps set properties of the controls. At least once generate code so that we've got the controls linked between the designer and the code. And then we'll spend a bunch of time back in the code writing the logic for whatever application we're building. For this particular application It was simply the button click handler so that we could set the text of the label. In color spotter it's going to be something similar to what we did in AppInventor except there'll be a lot of basic code to keep track of. What state the buttons are in, what state the winning count is in, and we'll go ahead and actually use subroutines right from the beginning rather than duplicating that code over and over again in order to make our coding more concise.
So next up a bit of a tour of Basic for Android and instructions on how to set up the emulator.
- Understanding the elements of an Android app, such as controls, sensors, effectors, and storage
- Exploring MIT App Inventor 2
- Getting started with Basic4android
- Building simple apps
- Testing apps on Android emulators and devices
- Sharing apps
- Creating hybrid apps with Appy Pie, Make Me Droid, and AppMakr