We'll come back and we are going to implement a second activity.
And we're going to prepare something inside of that activity, so let me just enter a name here, press
start and then you can see we get over to this activity.
So that is the goal of this video.
But on top of that, we are going to prepare what will be displayed in here.
So not the UI itself, but the data.
All right.
So let's get started.
First of all, let's create a new activity.
So here.
Right, click new.
Activity and I'm going to create an empty activity.
And this one will be called.
Quiz question activity.
All right, that's created and for this one, I want to have the same UI settings as for my other activities,
so I'm going to go here and I'm going to copy that while we don't need this precise part.
But the other two I want to have in there.
So the no action bar theme and also the on screen orientation should be portrayed for this activity
as well.
So our quiz question activity.
And actually, at this point, having an action bar isn't such a bad idea because then we can potentially
go back.
So let me get rid of this no action bar scene here.
All right.
So that's the first part of this activity then.
The next thing that I need to create is a validation that the user has entered something.
So if we go here, I want to have a validation.
So if we start and no text was entered, then I want to let the user know with a little toast.
So let's go to our main activity, because that's where the magic happens.
And then let's get the button start, which is the start button here.
And once we click on it set on Click Listener, I want to execute some code.
So first of all, we check if our edit text et underscore name.
Thought text.
Two string is empty.
So here it is, of course, going to be required.
So where's that from?
Well, let's go over to our resources, because here in our layout activity, we had this card for you
in which we had this text and so forth.
But what's important is this added text compact.
So here we need to create an I.D., which will be Etty name, because now we can access it and see if
there is an entry or not.
So what I'm saying is, is the text to a string empty?
So is it actually an empty string in there or no text inside of this field?
And if that's the case, then I want to inform the user about that and I'm going to use that.
Therefore, this toast feature and how you can do that is you enter, make text.
And then it creates a up make text and you need to pass in the context so it will be inside of the context
of our main activity.
So it should be shown in the same screen, then we need to enter the text that should be displayed.
So please enter your name and then the length of the toast.
So toast that length short.
And finally, we want to show this, of course.
So overall, it's going to look like this make text, please enter your name post length short.
Duchow.
Now, let's test that.
So let's click on Start when it's empty and you could see please enter your name into something there
and start again and now you can see nothing happens.
But of course, at that point, we want to move over to the next screen.
So we want to move over to our quiz questions activity.
So let's just do that.
Let's say, OK, if the text is not empty, so this added text, then let's create an intent which will
move us over to this other activity.
So we create a new Volp intent, which will be of type intent.
And here.
We need to import intent with all enter.
We need to say from which context we want to start and this will be this class here and then to which
class we want to move over to which activity will want to move over.
And here it will be the Java file.
So here, colon, colon class, that java.
Now, at this point, we, of course, need to start the activity and that is done with start activity,
with the intent that we prepared.
And we can also execute finish here, which will close to current activity, so we move over to the
other, but at the same time close this activity right here, which is our main activity, because in
the end, we want to be inside of the case until the user is done.
And then we come back to this page or to this main activity.
All right.
And now let's prepare our questions so we have questions and requests.
Right.
And that is the most important part.
Pretty much.
So let's go ahead and create a new class, which will take care of that.
So I'm creating a new court and file class and I'm going to start a class here.
And this one will be my question.
So I will define how every single question is going to look like.
Now, the thing is, this question class will not have any specific features and functionality.
The only thing that it will have is data information.
So it will know about the question text, so to speak, to imaged and the different options that there
are and which one of the options is correct.
So I'm going to do that as I'm going to do that with a data class, because this question class doesn't
need to have any function.
So it just needs to be a very basic data class.
So I'm just going to say I need to have an idea of type integer so that I know which question I'm currently
looking at.
Right.
And then you can, of course, now go ahead and add all of the other features that we want to have inside
of this question.
And by the way, these need to be.
Brackets, so not the curly once, but the rounded ones.
So I want to have the ID and then what else what I want to have now tried to think of the different
variables that we need to have here when creating a question.
All right, so we need the question itself, so question which will be of type strength then the image,
which it's uncommon.
Which will be of Top End.
So I'm going to assign an integer to each image.
Then option one, which will be of type strength.
Option two, option three and so forth, so all of the four options that we have, option one to three,
and then finally, I need to know which one of those four options was correct.
So Volp correct answer could have called the correct option as well.
But I'm just going to call this one correct answer, and that will be an integer.
So I'm just going to store the value one, two, three or four in there in order to know which one of
those is correct.
All right, and then, of course, I need to have all of the questions and there are multiple different
ways how you can do that, you could have an example file or JSON file, which contains all of the different
questions.
But in our case, we are going to work with constants.
So we're just going to create a new file here.
Scotland File, which I'm going to call Constance.
Which will just be a file and we're going to use object and call this one Constance.
So in here, I want to have all of my constants, and the thing is I will create one constant which
will contain all of the questions, so.
Fun get.
Questions, which is going to be a concern, but it's going to be a function which returns all of the
different values.
So here we're going to say that it's going to return an array list of questions.
So what I'm doing is I'm going to use this, get questions function in order to get all of the different
questions and what type of well they are question type and they are in an array list.
So basically, I want to have an array list which contains a bunch of questions.
And every single question is, of course, to have all of this information here.
As you can see, we needed to question the image, the options and so forth.
So inside of these questions, what I'm going to do is I'm just going to say, OK, let's create this
question list, which is going to be an array list of questions.
And for now it's going to be empty, but then I'm going to fill it up.
So, for example, question one will be of type question, and then I'm going to assign that idea.
And as you can see now, I need to assign all of the different values.
So the first question will have the ID one.
I will have the question, what country does this flag belong to?
And of course, you could say, OK, the question is always going to be the same.
So why do we even have this question in there?
Well, the thing is, this is a blueprint for you.
So if you decide to adjust the questions, then you can do so freely.
All right, so it's not necessary for this specific example, but it's going to be super great for your
own applications.
So then the next thing after the question is the image.
So we saw here in our question that we have the image as an integer.
Well, that one is a little confusing, but the thing is that our drawable dot and then, for example,
our background that we used is in fact of type integer.
So it's going to return an integer.
So now, of course, I don't want to use the background, but I want to use other images and you can
get the images from the course so you can download it inside of the course.
And they are attached to this lecture.
So I'm just going to paste them all in here.
You can see it's all of those images here.
I see Flag, Argentina, Australia, Belgium and so forth.
So now, of course, we can use the image that we just downloaded.
So, for example, I see a flag of Argentina, which will be this one here.
And you can also see it here on the left hand side.
OK, so the next thing that we need to pass is option one, then option two.
Option three, an option for.
All right.
So let's enter some options here.
For example, Argentina, which is the correct answer, then Australia and then option three, which
would be, for example, Armenia and Austria.
And then finally, we need to tell which of the answers is the correct answer.
So is it option one option to option three, option four?
So I'm going to say it's going to be the number one.
So here it's going to be the value one, which means Argentina is going to be the correct answer.
So let me bring that into a more readable format.
And now you can see that we have all of the different values that we had for the question.
Katie here so far, our data class, so now our question itself is correct, what is missing, though,
is, as you can see this get questions, function should return and the list of questions.
So let's add this question that we just prepared to our questions list.
So questions list, start, add.
And here we add our Q one or question one and then we return our questions list.
And with that, our function will be happy.
So no more errors.
And of course we only have one question.
And now instead of bothering you with all of the different questions that we need to put in here, I'm
just going to copy them from the prepared code that I have here.
And you can, of course, copy it from there as well so that you don't have to type in all of the questions
manually.
OK, so I'm going to put them just.
Underneath the point where I had my first question, so in here, I'm going to put all of the other
questions, I know at this point you could be creative and create your very own questions with your
own answers and your own images.
OK, so feel free to do so now there is one important thing left to do so that we can actually see if
that worked, so if we can actually work with the questions that we have there and that is not going
to be to display them yet.
But what I'm going to do is I'm going to create a new questions list variable here, which will be from
my constants that get questions.
So here we had this constant class or it's not really class, it's an object, right?
It's an object which is available from everywhere.
That is the power of it.
So I can just go out and say concerns, get questions, and it's going to give me all of the different
questions that we had.
And now we can test if that worked by using a longer statement.
So I'm going to say, look, I it's going to be questions size.
For example, how many questions do we have in there that the message should be is questions?
List that sites.
All right, and at this point, we will be able to see how many questions there are, so let's run this
and see if the LOCKETTE is going to offer the information.
Therefore, you need to open the Lockette here to bottom.
Said that too verbose and and questions because otherwise there would be way too much information here.
So if you enter a question, you can see it's filtered.
And now let's go to the next screen.
And we can see question size is 10.
All right, so the questions are there, we can get them to this activity, to this quiz questions activity.
So that means that we can now go ahead and populate our screen accordingly with this information.
All right.
So I'd say let's go to the next video where we're going to do that.