Welcome back.
And this video, I would like to get to the point where I can enter a name and then click Start in order
to get to the next screen, where then we want to eventually display the questions with the options
that we can select from.
OK, so in order to get there, we need to create another activity.
OK, so we have this main activity inside of our package here.
But now let's go ahead and create a new activity to which we can then change.
And I'm going to select empty activity here and the name of this second activity.
For me, quiz questions, activity.
So here you can just enter with questions.
Activity, because this is going to be the second screen of our application and that's where we're going
to move over.
So generate the layout file.
This is set by default, and I really want this to be activated as well.
It's not going to be the launch or activity, which means it's not going to be the activity to which
the user gets so near the screen to which the user gets once he starts the application.
So let's click finish, and now we will have this additional activity, you see.
So this is the quiz questions activity which has pretty much the same style or looks pretty much the
same as our main activity.
The only difference is the name here and the layout file that is loaded.
So now the associated layout file is this activity quiz question XML file, which currently is empty
and it will stay empty for this video.
But in the next video, we're going to fill it up.
So the goal for now is to make sure that we have the questions ready and that's what we're going to
prepare.
In this video, we're going to see how to prepare all of the beautiful questions and even move over
to this screen.
So in order to move over to the screen, I'm going to get started by allowing to click on the button
and the button that I want to be able to click on is going to be our.
Button in the activity main.
So here you can go to this linear layout with this one button here, right?
So it's this button that says Start, so this button will need an ID so that we can access it.
OK, I'm going to give it an ID, and I'm going to call it button start make.
So Button underscore star two.
You can call the button capital s start however you want.
OK, so now this button start ID is what I will need to use in my main activity.
So let's sort up this button volume, and I'm going to call the button start, which will be of type
button and we need to find the view by its ID.
So our DOD ID dot.
And it was called button start.
So now we can use this button to implement the on click list and their method, as we have seen before.
So for now, what I want to do in here, I want to check if the text that the user entered in here is
not empty because if it is empty, I don't want to be able to move over to the next screen if it's not
empty.
So if there is a name, then I want to be able to move over to the next screen, which will start to
quiz.
So here, let's check if the name was entered and therefore we need to get the data from this app compered
at its text.
And I'm going to call this one name.
So here the idea will be to underscore name it stands for and its text.
OK, so here add it text and now I can access this at a text in my main activity.
And of course, accordingly, I will need to create a name property here, and this is going to be an
added text.
So let's find the view by its side.
And this was our ID dot E.T. on the score name Mike.
So.
So now I can access this name.
And how do I want to access the name?
Well, I just want to find out if it's not empty.
So I want to check if the property that is inside of this E.T. name, that's called text.
Is not empty.
So we can check, is it not empty or is it empty so we can do either way, we can just check is empty
because if it's empty, then I want to display a toast to the user.
So here, toast, make text and by the way, we'll need to import toast for that.
Make text as let's see here.
Make text this one.
And first, we need to pass in the context, which will be the class itself.
So this.
Posts should be displayed in the main activity, and then I will tell the user to please enter your
name.
OK, and then how long should it be displayed?
So here tostart full length long and then finally show the whole thing.
OK, so let me put that in a second line.
So that is going to be a little more readable.
So we have this edit text now and we check if it is empty.
Then we make a text, so we display a text.
So let's see if this is going to work.
And there we are.
So John, let me in three and click start.
And you see nothing is displayed.
Let me enter nothing and press start, and you can see that it says, please enter your name.
So once I enter something that works so well, it doesn't do anything, basically.
So what I wanted to do instead is, however, to move to a different screen, and that is something
that we have not done before, which is why I need to explain you how it's done.
So basically, we create an intent and this intent says from which activity we want to move to which
other activity.
So let's just set it up and then it will make a lot more sense.
So here we say visual intent, which is of type intent, and we need to import this clause intent.
So once we do that, you can find it here.
It says intent.
Here, content intent, and if you're wondering why is complaining about this button start, well,
that's a really good question.
That's because it's not happy with names that have an underscore.
So this is called snake case, where we have underscores every now and then.
And then there is the camel case where you can rename it to, for example, button start like so and
then it would be happy with the name.
Same goes here, itie name.
Like, so then it would be happy.
So the idea is happy.
So in the example, it doesn't care if you use it like this, but in variable names, it's not very
happy if you use that camel case that on this course.
OK, so now we have this intent.
And what I'm going to do here is I'm going to, first of all, say from where I'm going, I'm going
from this activity.
So from the current context, from the main activity over to my quiz questions activity.
Now this is a Java file, so I need to add class to Java after two columns.
That's just how it's done.
And this is basically how I define where I'm moving.
So this intent will now allow me to move from this activity to the quiz questions activity, which is
this activity that we want to go to.
And now this by itself will not be enough.
We also need to make sure that we start this intent because otherwise this intent will not do anything.
So we start the activity and here just with one, why?
Like so and we need to pass in the intent.
Now this by itself would move us over to the other screen, but it would not close to current screen.
So let's test that real quick.
So welcome, and let's say I and Dennis.
Let me start, can you see it moves me over to this next screen, which is currently an empty screen
that doesn't have anything in it.
And I can now still go back to the screen that I had before.
Now, if you want to avoid that, you can just add finish here.
So call the finish method, which will finish the current activity, which means it will close the main
activity.
So let's test it once again.
Let's entered the name.
My name is Dennis.
I'm going to kick start and then I go back and you see it close the application.
So now we are at a different version of the application.
That's a little confusing because I added I two instances of the application.
So let's start.
Click back and you see we get out of the application entirely.
So if you want that, you can just call finish here.
OK, next, what we will need to create is going to be the data model of our questions.
So inside of my namespace here, I'm going to create a new Cortlandt class and it will be a data class.
So the data class that I'm going to create is going to be question.
So not questions, but individual question.
So here I can define what kind of parameters I want to have for this question.
So what do I need to know about each question?
So what kind of information do I need?
And I need to have the question itself.
I need to have the image and I have to have the different options as well as needed to know which of
the options is correct.
So let's just set those up.
And by the way, it's also good practice to have an I.D. so that we know which question we are at.
So let's say we want to have the question.
So now think about it, what would be the data type that we want to have for the question?
Well, I want to have a string.
So the question should just be a text, right?
Then we need to have an image and think how images in Android work is that you can create them based
on INTs.
So the image will be an integer, which just means, well, location inside of our resources.
OK.
And then we need to have the options.
So option one, as well as option two, option three and so forth.
So you can just add those here.
This one will be two, then we will have three.
And finally, we will have four like so.
And of course, we need to know what the correct answer is.
So here, correct answer is going to be of Typekit.
So it will just be the number.
So this one will, for example, be value zero, one, two and three.
And the correct answer will just hold the index.
So either are zero if it's answer one or option one and one, if it's option two and so forth.
That's just how it calculates, right?
Typekit.
That's just how computers are counting, right?
Starting from zero.
Those weirdos.
OK, so now let's go over and set up how we can actually access these questions.
So therefore we will need to have another.
Object and this way or this time, it will be this one here, just an object.
I'm going to call this one, Constance.
So in here, I'm going to store all of my different constants that I want to have.
For example, the user name, then the amount of questions, the correct answers and so forth.
But first of all, I need to have a function which gives me the questions, and I can then call this
function from my questions activity and get the right question or the next question that I need to display.
We know how a question looks like, right?
It's this class here, this data class.
And now I just need to call this function, get questions and it will return all of the questions.
So I'm going to create an array, a list of questions.
You could, of course, also get the questions form an X mail file or adjacent file or another resource.
And you're going to learn how to use JSON files later on.
But we're going to keep it simple and we're going to just hardcoded them into this constant file.
OK, so here inside of this file, we're going to create all of the questions that we want to have.
So therefore, I need to create a questions list and it will be and the release.
So I'm just going to say it's an array list of questions sort of individual question items, which is
why I don't say questions, but question here.
OK, so this question list now needs to be filled up.
So how can we field this question list?
Well, by creating individual questions.
So let me create one question which will be of type question.
OK.
I'm saying this would way too often so don't make a drinking game out of it.
And then I start by answering all of the details that the question needs to have.
So hover over it.
And you see, we need an I.D., we need the question itself, and then we need to image.
And by the way, I realized that I called this questions, and I'm not really happy about that.
It should be question.
So here, let's change that real quick before we average use it, and now we can use it.
So we need to add question image option one, option two and so forth.
Let's start with the ID.
And for the first question, we can go as simple as give it an idea of one.
OK, we don't start at zero at this time.
Not this time.
Then we can add the question What country does this flag belong to?
And then we have the question mark and we separate the entries now.
The next one will be the image, and the image is something you can get by using the following approach.
You see this here i CBG will be internally treated like an integer, which is why it's fine to use it
this way.
OK, so here you see, the image has to be an end, and the cool thing is are to draw all that whatever
image is used will return an integer.
Now, of course, I don't want to have or two used as a background as the draw for each question I want
to have.
I want to have separate images, so let me get rid of this and instead import all of the images that
I have prepared for this.
So you can just drag those troubles in here from my other project.
And you see here we have all of the flags.
So this is Q.
Wait, I assume this is a German flag, faji and so forth.
Now we have all of those beautiful flags.
Now let's go back to our questions and use those.
So here, what country does this belong to?
And I'm going to start with this beautiful country of Argentina or the flag of Argentina.
And then I need to add the options.
OK, so I have to draw bill for Argentina and now I can go ahead and enter option one.
So let's say here we'll just have to come up with some possible answers.
So I'm going to say this is Argentina, then I'm going to say this is Australia as the second option.
And this is the like.
So and this, of course, has to be outside of a given strength.
So this is option one, option two.
Now let's add option three and therefore we need to add a comma and option three would be Armenia.
And then finally, Austria.
So now what is going to be the right answer, which is the final property, and I'm going to use the
correct answer being one.
So it's option one.
So now, accordingly, we need to add this to our questions list, so now we have the first question
and then we can go ahead and add the Q one sort of question one to our questions list.
And of course, we need to return something.
So you see this fun quote get question needs to return to the list of questions which this questions
list, by the way, is so we can just go ahead and return to questions list.
And now our code doesn't complain any more.
It's quite happy because we are following the procedure and following the architecture that our project
wants.
So now you can just go ahead and add additional questions.
I'm just going to copy and paste them in here because I've just prepared nine questions here.
Let me add them.
You can, as I said, really be creative here and use very different images, very different questions,
an option and image options here.
So here the flag of Kuwait doesn't seem to be part of my options.
I think I need to use New Zealand.
Then let's use New Zealand.
Here.
OK, so now I have my nine different questions.
Beautiful with the individual items, with the different options, he has one, even none of these.
And yeah, you can just play around with it and.
I had whatever questions you can come up with, as many as you want and so forth.
So now how can we actually test this?
So how I'm going to test this is by using the locket, and we've not used the locket yet, but that's
what this course is for concealing you thinks so.
Let's learn how to use this new thing and therefore let's go over to our questions activity because
once we get to this question of activity, I want to load the questions list.
OK.
Like so and I'm going to get that from my constants start.
Get questions.
So this is a method that we just prepared, right?
Or this function.
And what it does is it returns a bunch of questions for us, which is amazing.
And now, in order to keep it simple, I'm just going to log this saying the question size.
Or questions list size is.
And then I'm going to display the amount of questions that we have here, so all the questions list
that size.
So now import lock here, in order for this to work, so Android due to lock will allow me to use this
a log entry.
So in order to see what is displayed in the lock, you need to open up the log kit.
So this is locked here at the bottom.
And now let's run our application and actually search for questions.
A list like so questions list like I entered it there, and maybe I should be super precise here.
So questions list.
OK.
And you see, there's nothing there.
And that is because we never actually executed this code, so it will only be displayed in the lock
at once.
This line of code is executed.
And how can we execute it?
Well by calling the on create method?
How do we call the UM, create method of the quiz questions activity while by opening up this activity?
And how do we get there?
Well, a bunch of stupid questions, Dennis.
Come on.
Well, it's by calling this intent here in our main activity.
So here this beautiful main activity, and that is once we enter a name and we click on the button start.
All right, let's do all of that stuff.
So let's enter Dennis and click on Start.
And we are on this next activity, which is empty.
But now let's look at the logcat and you see the questions.
List size is nine, so that worked.
And now we know that we can move to another activity and we get the questions at least over to this
other activity.
So that's super powerful.
In the next video webinar, you set up the questions you, I, and we're going to connected UI to our
model.
So we have created this model, which is this question here.
By the way, if you were wondering what it is, the data class is the model of a question and we can
now connect it to our UI.
So see you in the next video.