Now, in the previous lecture, we created an Android virtual device to run and simulate an application.
So you know what that means, we are now ready to develop a basic quiz game map.
This will, of course, help you better understand the structure of a mobile app, but it will also
teach you the different components of Android apps in general.
So let's start.
Go to Android studio, start a new Android project.
Now, of course, there are different types of activities for phones and tablets.
Well, just select an empty activity and click next.
Now, what to call the application.
And I'll develop it with Java.
Now, you can, of course, select the SDK here for whatever Android version that you want to use.
Now, before selecting it, just be sure that you've downloaded it and it is available on your computer.
All right.
So let's look at the SDK manager before creating a project.
Click on Configure on the bottom right corner.
Select the lowest version of Android, your app will support in the minimum SDK field.
Now, before using any Android version, we should install its SDK platform package.
So I have SDK packages for Android nine with twenty eight API level and Android 10 are with 30 API levels.
So as I said before, we can use one of the Android versions, eight, nine or 10 throughout the course,
so why don't we just go ahead and install Android 10 queue version with 29 API levels?
And I can select the checkbox and click, OK?
And I mean, these components will be installed, OK?
And you got to wait for a little bit.
All right, so finish.
So now we have the SDK package for Android version 10 Q.
And we can go back and continue where we left off.
So I selected the minimum SDK for the project.
And finish.
And bump, bam, just like that Android studio main window opens.
Now, you may remember that we examined the file structure of an application before.
Now, if this is the main activity, it's the entry point for your app, so when you build and run your
app, the system launches an instance of this activity and loads its layout.
So under the red folder, there's an Excel file defining the layout for the activities user interface.
Let's first create a user interface.
So this is the default layout and TextView with a split view in the upper right corner.
We can edit the user interface on the XML file.
Now, change the layout to relative layout, and it is a view group that displays child views in relative
positions.
So we'll delete the default TextView, I'm going to add buttons and text fields in the design section.
So first of all, add a button and add an attribute to a line at the bottom.
And I'll click true.
So I want to change the size of the button and create four buttons just like this so I can copy and
paste to create the same buttons.
Now add to Texas.
One for the score, one for the questions.
I'll also add an attribute for this to a line at the top.
And quick to.
I'll add another TextField.
Now we're going to need a larger area for questions.
So let's say I add an attribute layout a parent top.
I'll center this horizontally, but let's change it on the XML side.
So this is the text for you that I want to change.
This is how I add an attribute in the code.
Now it's in the center, so let's add a margin to left for this TextView.
All right, that's a little better now.
So we can now give some names for these buttons and text views.
Buttons will be the answers.
All right, so now we can create functions in the main activity file.
First, define buttons.
So we need to import four button.
And define text views as score and questions.
Now we'll create the activities in the uncreate method.
So when an activity first calls or launches, then the uncreate method is responsible for creating the
activity.
Now, here's the fine view by IED method, and it'll return a few object.
In fact, we call all the objects using this method.
And these objects should be TextView.
Now, to specify an action when the button is pressed, will set a click listener on the button objects
with the set on Click Listener Method.
So if you press enter while you create a new listener, Android studio will autocomplete the rest of
the function.
So now we can create this method for all buttons, all the answer buttons.
Now, before completing these methods, let's let's first create a new Java class for the questions.
So, right, click on the project and create Java class.
Now, let's define a string array that will.
Keep the questions.
And.
I'll create some questions about Android versions.
What do you think?
Next, I'll create another array for the choices.
And I'll mix the order of the choices for each different question.
And create the last array that will keep the correct answers in order.
I recall both questions and answers will need to create methods that will return them.
So I'll create them for all answers and choices.
So as you can see here, we created a two dimensional array for choices to match questions and answers.
I'm not going to really dive too deeply into this topic because it's not really our subject now.