Transcripts
1. Class Introduction: Hello. This class is about
how to develop a simple quiz app
in Android Studio. In this class, we'll be learning about how to create a new
Android Studio project. How to create a new
file based product. How to add data to Firebase
realtime database. How to retrieve data from
my best realtime database. How to create a database
using DB browser for SQLite. How to import a table into
Firebase realtime database. How to validate
answers inside quiz. How to this base coat and timer. How to display high scores. How to change the text
inside action bar, how to create an Exit
button in an Android app. You'll also learn
about how to structure tables in a database
inside DB browser. And then how to export the database to
Firebase realtime database. For this app will create a
database with three tables. Each table will be
construed as a level, and each level will
have ten questions. We will keep this app
as simple as possible, and we will not be
using any fancy way. At the end of this class, you'll be able to create
a simple quiz app in Android Studio where
the data will be stored in Firebase Realtime Database. Welcome aboard. Let us start this class now.
2. Creating New Project: Alright, let's create
a new project. First, double-click on Android Studio and
let us wait till it loads new project. Let us select Empty
at 2D. Click on Next. Here. Let us name application. Let us say fire quiz. You can select minimum
SDK, determent 21. Okay, no pecan finish. We have our project ready. You can see we
haven't manifest here and we have the basic
empty activity. So we'll leave it here. And we'll create the
file-based profit.
3. Creating Firebase Project: Previously we have
created this project. So now let's open a
browser. Let us say edge. Here, type Firebase console. How Firebase console. Select Firebase console. So let us click on
Create a project. We need to name
our project first. Let's say base quiz. This will be the identifier. We need to pecan. I accept. Now click on continue. For the time being, we will
not sell this analytics. Create Project.
Click on Continue. Now, since we are going to use only the Realtime database will use the basic plan itself, will not update our
plan as of now. So select an Android app. Now, we need to register our replication
integrand Rstudio. We help create a new app we
need to reach to that app here we need to copy
the package name first. Here you have package name. We need to copy that
here. We need to give a nickname. It is optional. Even if you leave this
empty, nothing happened. Next, we need to give as a table in order to get SHA-1 here. Before doing this, let's
select File Settings. Here, setup experimental,
and here makes sure that the first option
is not selected. We want to build this list. By default, this
will be selected. Make sure it is selected. Click on Okay. Now
refresh this gradient. Now select Tasks. Appear inside and
radio signing report. Double-click on that.
Md5, SHA-1, SHA-256. So now copy etc, one basic here. Nope, pick Honda is trapped. Next we need to download
this JSON file. Download Jason. Let's copy this. Select project view. Here inside the app. We need to paste it here. We need to go back to five A's. Click on Next. Now
we need to add these SDKs to over Android app. The ****, given the
SDKs we need to add. So first we need to
add Google services. So we'll click on Copy.
This we need to do it. Dot credit will go to Android. Gradle scripts inside the
project. So we'll paste it. Now we need to open Module,
build-up Gradle module. So here we need to remove, apply plugin and
simply reduce ID. Finally, we need to implement
that Firebase package. Here. We have I didn't knew dependency. So basically continue.
Click on Next fear. Saying you're ready to
continue to console creator. And we have set up the
Firebase for our project. Now let us see what
are the options we have to instead build. We have authentication database, real-time database, so we'll be using only realtime database. Let's click select
Create new database. You can choose the
location here. Three locations. Click on Next. And biosecurity rules. Let us say starting
testimony, bonding here. Click on enabling. Currently
the database is empty. We'll go to rules, and
here we'll make written. It is not required, will
only be reading this, will make it a read through. Next, we'll create the data.
4. Adding a Question: And now we'll see
how to create data. Since we are using
Realtime Database, we need to copy the
dependency here. We'll use Firebase database. Since we are using Firebase, BOM believe not specified it. Let's speak version number here. Let us click on ST. Now. Now next, we'll go to
our Firebase database. We help create a new
Realtime Database. Now, at child here, we need to give a name to let
the name b1 ladder value. So again, let us say
question. Let us see. What is the capital
of India Related? To add the options as well. Let's say option one. The answer here. So here we can specify better option 1234 or we can directly copy
the answered safe. We'll copy this. Now we have one question.
Question number one. Sorry. We have one question. What is the capital city of Indiana? We have options and
we have the answer. We are not going to create
the entire data like this. This only to show how we can create in order to
access this application. So first we'll
create new activity. Right-click here. Select New Activity, select Empty Activity. Will never test quiz
activity, activity quiz. So click on Finish. You have XML file here. Before. Simply specify
a small button here. Instead the actor domain with the Moody's picture here button. Instead of hello world. Let us say start
with increase a bit. Let us say 150. Height will use 50. Will also change exercise. Let us say we have a button. Whenever we click
on this button, quiz equity should be open. We go to main activity, create a pattern object button. In this video, we'll give an ID button, btn. So now we need to create
a fence for this bottom. Set, the non-professional
begin start dot set on PFAS. Now, quantitative. Content equals new intent. Main activity dot this. We need to open quiz after
class. Start activity. We need to do intent. Will
reach squeeze that booty. So we'll use LinearLayout. Linearlayout will make the
orientation to vertical. Orientation will
display the equation. Let us use text to be matched pair and height will be wrap content and PTX size. Excise, let us say 20. Text color. We'll set some
different color other than black will use. We use blue color will also
give an ID ID question. We'll also set the margin. Margin, let say. Similarly,
we'll create four options. Here you have question, great option one, option
two, option three, options for recreate another to be match parent margin. We'll use two extra years. We need half the width. So we'll use a layout. Some here. Let us say one. Width will be 0. Content. Layout
weight will be 0.5. Excise. Exercise,
let us say 14 color. We'll use black option. Copy the same again. The spring it would be option will copy this LinearLayout. Attributes, objects for
question and answers. Now, we create a purchase
for all those pictures. Equals find humanity. Question.
5. Displaying Question in App: And we hope created
a question there and we have set for
options and an answer. Now, we will access the
data here before that. Minute to use
database reference. Let us name it database
reference itself. Database setup. First, we should get instance for
database. Database. Difference equals
Firebase Database. Getinstance. By default, if you
use getInstance, instance of this
database will be taken. But sometimes we need to
include this address also. We include the address
of this database. Inside the instance. We need to use git
reference transect data. Data is inside one. If we leave it to you
get reference empty, we'll get the data off the root. We want data which is
present inside one. So we'll use will use
git reference one. Instead manifest we need to
add Internet permission. Users permission and name. We need to use
internet search for Intel Permission
Internet created reference for our database. Next, we need to access
the database and retrieve the data
database reference. We can add a value
event listener. We can also add single
value event listener. So we'll add a value
event listener. Whenever data changes
inside the database, will get a snapshot of it, the new value event listener. Now here we have snapshot, data snapshot inside
on data change. This snapshot contains
these values. Since we have given
the path as one, we get these values
since at this snapshot. In order to access that.
First we'd set the question. Question and toxic
extra snapshot dot child question, getValue. We need to get the value in
string format, string dot. Similarly, we will set options. Once you've created it.
String variable for answer. That will not use it now, we'll use it later, since we have only
one question we are setting in the question and the options directly inside
the data change function. So if we have
multiple equations, we need to loop
through the snapshot. Since we are said
the question and the options. Let's click on one. And now let us click
on Start here. You can see here we have the question and we
have four options.
6. Validating Answer: No. Instead I took the quiz, will create a Validate button. At the bottom button. 150, type B 50. Let us say validate, fix size. Next we give margin. Margin, let's say 20. Layout gravity center
will also give an ID. Within Validate.
Once this button. We can validate here. So we'll push this
button to the bottom and will increase the size
of the answers here. Layout. Let's wrap content. We'll do min-height.
Min-height, let's say 100. It will make them
center of gravity, center of gravity, center. We'll do margin between
both the answers here. We have created validate button. Now we'll create a
reference for that button. Here. We have also created an answer available
instead on data change will also set answer, answer
equals snapshot. Dot dot. Get value will also create
selected option variable. Int. Option equals 0. Option is 0, no
option is selected. When it is 1. First option is, whenever we select an option, we should highlight that
particular option. Option one. What I'm going to
be clicking option, we should not be able to
pick another option again, for that, we'll
create a function. So let us say disable
all textures. Db option one dot, set, a couple fonts. Now we need to use that here. Double-click also we need to highlight option we
have selected for that, we need to set the
background color to the top. Here we have used available
option equals one. For that also will
use a function. So let us say highlight option. And inside that, we need to pass the selected option
variable. In adoption. Switch. Option case
one, case one. These we need to set the
background to DB option one. Option one dot
background resource. Android dot dot color. Audience will set blue, blue highlight option. And we need to pass
the option option or else instead of using the
select option variability, we can directly pass
one to be the same. We click on the button you to show us wherever
we have selected the right option of
not begin validate. You wanted to close. Now,
when we click on Validate, we need to get the answer. For that will also
create another variable. String answer. Selected option. Default option is
not equal to 0, which means we have
selected somewhat the other option, not equals 0. If option not equal to 0. Instead that we'd have two
options. Answer is right. Selector option equals answer. If Salford option
equal to answer, we need to set the background
color of option to green. Else we need to set the
background cutoff option to read and we need to highlight
the correct answer. So here we have
four options and we need to manually check
all four options. So once again, we'll
use with ten k's. We hope created highlight option will create one more option. This time instead
of pilot option. Let's see. And here instead of blue, we'll use green. Green. Instead of using two
different functions. You can also use same function. And along with option,
you can also pass the color will call option. We need to pass the option. Similarly for wrong optional. So we'll do that. We'll
create another time, let us say wrong option. And here we'll use the red color instead of green option. Now in third wrong option, we also need to highlight
the right answer. Dot equals answered. Minute to set. Option equals option one, dot. Get string. Inside the else part, we need to highlight
the right answer also along with the wrong answer. For that, we'll
use DB option one. It got toString equals. We need to set the
background color to green. Now, let us take this
logic works or not. So now let's click on start. We have four options here. Here we know the right answer, so we'll select
the wrong option. You can see, once we
select this option, not able to click
any other option. So let's click on validate. You can see here this is Strong alternate and this one
is the right option. Will go back. We click on Start. By this time we'll
select the right option. You can see here is
the right option.
7. Installing DB Browser for SQLite: Now we'll download DB
process for SQLite, will go to a chugging here
type DB browser for SQLite. Here you click on that. We'll scroll down. Here we hold different releases. So we'll go to latest version. Here. A 100 download
will download. Standard installer for Windows. Download is complete.
We'll install this. So double-click,
click on Next here. I accept next, and we'll
select Desktop for SQLite. If you want, you can
change the location. We'll click on Next shortcut for DB2 process. Before that. Before it opening DB browser will create
a folder naming Databases. Folder. Name it databases. We'll save our database
inside this folder.
8. Creating Data: And I will open this DB
browser. So double-click on it. Here, the top, we
hope new database. So click on new database. So it is asking us to choose
the location as well. We'll go to databases and
let us name the file as sample will be consumed. No, it is asking us
to create a table. Name the table as level one or else will not do the
space here, level one. So we need to add fields. The first field
will give it as ID, integer and not null, primary key,
auto-increment and unique. Next we'll add question. Next we'll add option one next to option two,
option three options. And finally, we need
to add answered. Click on Okay. In order
to view this table, we need to go to Browse Data. And here select the table. Currently we only
have level one. Here you have ID,
question option one, option two, option three
options for an answer. So at the top you
insert new record. You can see here we
have a new record. Insert records into each table. Will create level
two and level three. Here click on Create Table. We have created three
tables and we have inserted ten records
into each table. Here we have a question. And if we have this question, we'll copy this question. I will paste it here. Similarly will add 29
more questions to it. Now, we have either
gone questions. You can see here level one, level two, level three. Before that into
Firebase database. Let's open it here. We'll remove this question
and we lead three records. First one, let's say level one, we'll just leave it empty. Similarly, we'll
add a level two. Level three. We need to import the data
from the NDB process. Further. We need to export
here File Export, Export As GSM will
select all three. And we need to
choose the location. So we'll save in databases. Select folder, export completed. Now we can see here we
have level 123, DSM-5. Inside the Firebase
be called level one. Select Import DSM. Go to databases and level one. Now click on Import. You can see here all over ten
questions imported here.
9. Adding Levels: It will create an indirect duty. Only three buttons, level 123. So go to File New
and select Activity. Select Empty Activity will name this sense level activity. Inside activity level, we will use constraint
layout only. Here we'll just create three
buttons, status button. Imagine, let's go
to top of parent. Left to left off parent
and write to write off parent will also
give you an idea. Began level one. Level one. We have
the button here. So now we'll create a
level two and level three BBN level tool. And we need to change
the constraints. We need to remove the
opposite of parent. Do bottom-up. Level one. And similarly, we need to create the button btn level three. Here, level three,
top to bottom up to the level two. Main activity. Now what we can start to open level activity instead of Quiz activity, reopen
level, activity. Inside level that we need
to create a transfer these three buttons. Button. Beginning of a new intent. To do this activity, we need to send a text. Dot. Name will be level name, level name inside databases 111. Start activity. We need to repeat the
same for level 23, also, insect quiz activity. We need to go to the top and
the need to create a string. Here. We have answered select option. We need to create
the level name. Will get the level
name from intent. Level name equals get string extra. Student name is level name. Inside the get deference. The path should be
level limit of one. Now we are given level
limit SETR event. If you absorb database. Instead each level we
have ten questions. In order to get ten
questions from each level. First, we will
create an ArrayList. We helped create it, at
least for option one, option two, option three,
option for enhancer. We need to store the
data in these areas. Here we are giving
level name itself, but if you wanted to get
each question snapshot, we need to use data snapshot. Each of the snapshot. Snapshot dot get children. Instead of loading the quadrant
directly into ArrayList. Question at the cushion loaded data into list. Now we need to create the question that we'll
use a separate function. Let us say Create question. Here. We'll copy this. Instead of using snapshot, we need to use list, dot. Get tan. We need to use index will create
two more variables. One is question number and other is index. Question number. One, index 0. We have used option three twice. Get. Here. We need
to give index. Since five based around
a couple of seconds to load the data initially will
disable all the options, will simply call the DoubleClick at the starting double-click. Whenever we create our question. Whenever the data is loaded, we need to enable the clip
will simply set it to two. We need to call
this grid question in order to load the cushions. Once this for loop is completed, equation, we use
create question. And even if you absorb
inside the for loop, we have used snapshot
dot child instead of ds. So we need to use DSS since ds. Ds will written each
individual question. So from that each
individual question we are loading
questions separately, option one separately,
and so on. Let's check whether
this works or not. So now we'll select
one level. Level one. You can see it takes some time and then we
close the question. Instead the database.
Open level one. So first question
will be under 0. You can check here. The first question,
we'll select option. Here. We cannot go to Next question because we have not created that button yet. Before doing that, we'll
check other two levels also. We'll go back, we'll
select level two. Now, here in level two you can absolute 00
is the first question. You can see it here. Set
up wrong option this time. We have already selected the correct option,
so that's validated. No callback. Level three. This time we'll choose
the wrong option. Will create the Next button.
10. Next Button: Now we'll create Next button
will go to activity quiz, will change the linear
layout to constraint layout. Constraint layout. We need to remove
the orientation. We need to add constraints. Next, we should be at top, top, top to top of parent. No need to place
the text to center. Since we are using with
test match parent, LinearLayout should be right
below the dv question. We'll add ID, LinearLayout ID. Let us say LL1. And this one should be
right below typical ocean. Top to bottom up, top to bottom off. Tb question. Similarly, second
LinearLayout will give an ID and this would be below LLVM, bottom off LL1. And finally, we'll place both validate and next at the bottom. We need to remove layer routing. Bottom, bottom to bottom off. Better. Validate should be
on the left side. Left to left off. We'll use the same attributes. Will create btn next.
And the different Cs. Instead of left to left off, we'll use right
to the write-off. Id will be pretty in the
next text will be next. Here. Instead of
left to left off, we need to use
right to the right of constraint. Right off. You can see here, validate
next, these are options. This is the question will
reduce the gap between options. Meantime, we'll make it,
let us say six feet. We need to create a
reference for next button, btn and btn next, findViewByID, BBN x. Now we need to create
an onClickListener for next button within the next clip. So whenever we click
Connect button, next question needs
to be loaded. So for that we need to increment the index and question
number when index is 0. First question will be
loaded when index is 1, second equation will be loaded, so we need to
increment the index. Index plus plus also
question number plus plus dv question. Before setting question,
we need to display the number q and rho plus. Approaching number plus, plus. And finally, we need to
call create question. Question. Whenever we
click Confirm option, the color will be changed. So we need to remove
colors and set the background to
transplant for all options. For that, we'll create
another function. So white color here. Copy this. Instead of blue, we need to set transparent. Transparent. Whenever we are
loading new question. There should not be
any background color for any of the options. For now we need to call
this remote color. Remove color, called remote color first and then
create question. Now, let us click on financing. Let us click on Start. We will choose 1111. Fun. We have a question, will select the answer. We can also click
on Next without selecting any option or
without validating it. Question 3467 in nine. If we click on Next, now it will crash because
we have not written the appropriate logic
here inside btn. Next, we need to go
to next question. We need to increment, we need to remove color or create question. So we need to perform
these four operations. If index less than nine, only when index is
less than nine, we need to perform
these four operations. Index equals nine. We need to finish the activity. We need to finish the quiz. Finish. Now click on Start,
select the level. So we'll select option. Next. Nucleotide on. The quiz activity is finished. We will take the
same for level two.
11. Calculating Score: A full-stack calculate IQ score. So for that, we need to
go into activity quiz. Here. If you look at
the design at the top, we have question. The question. We need to help dimer and score for that really create
another LinearLayout. Linear layout width to be
match parent that content. And this should be top to top of parent constraint layout. Imagine let's say some, let us say one will give an ID. Since we used both
L1 and L2, L3. This next view should be below
L3. Right, top to bottom. We need to give orientation, so we'll set horizontal only. We need to have for textures 0. Let us say 20. Layout weight, let us say 0.3. Color. Sorry, we'll say it. Next. Color, dark and
text size, let us say 20. Exercise. For this we need to do right? By month. Layout weight
we use 0.2 green, given green and we'll
remove the text. We'll copy these two TextViews. Text will be scored color. Let us sit. Bleu. Score will do black color. Black. You can see here we
have dimer extends code. Now we want to calculate score. For that, we'll create a transpose Db Db score. Now we need to calculate curve. That will create
a score variable. Initial value should
be 0 squared equals 0. We need to set the
initial score, DB score dot setText, score by ten. Since we have ten
questions and bite them. Selected option D equals answer increments
score plus, plus. Once again, we need to set
the text to DVI score. Set. The text should be plus. Now let us click on tenancy. So now let us be constant. We'll select the level
twos, right? Option. You can see a score
one by ten by ten. Next, we'll create a timer.
12. Timer: Now we'll be creating a
timer. Countdown timer. Let us say n initial
values should be null. We need to start our timer. For that, we'll create a function start timer. Start timer. We need to create a new
timer. Countdown timer. Here, we need to
specify total time. Along with dying gap. Total time will be ten net, so 600 seconds milliseconds. Gaps would be 1 second interval,
thousand milliseconds. We wanted to display timer
in minutes and seconds. For that, we'll
use string format, string, string dot format. We need to display
minutes and seconds. We'll use 0202 means, for example, if
the number is due, it will display 02
instead of two. And so the first one is minutes, second one is seconds. Now we need to and get
minute ten seconds. Total timer is 600 seconds, which is ten minutes. Time unit dot milliseconds. We need to convert
that to minutes. Duration is inside
the long allele. Now we need to display seconds. Once again, time unit,
not milliseconds. Seconds and this time. But here, if we leave it like this, the seconds will display
600 finite 9598 like that. But we want 5958 and so on. So for that, we need to
convert minutes into seconds. Then we need to subtract that from total remaining seconds. Time unit dot minutes to
seconds and a minute thought. Milliseconds talk two minutes. And law. Timer dot, dot. Now we need to set the
timer to our texture. Dimer. Dimer is finished.
We need to finish. The quiz. Timer. Will set. Text has done. Whenever we finish the quiz and before the time
it is completed. In such case we need
to stop the timer. For that. We'll create another
function. Let us say it. Canceled. We need
to check the time. It is not equal to null. Timer dot cancel whenever we finish the quiz and before
the time it is completed. So in such case we need
to cancel the timer. Cancel IMA. Similarly, whenever we
press the back button, even in such case we need
to cancel. The timer. Will go to bottom, right on back pressed.
Cancel timer. Finish activity. So Finish. Now, we need to start the timer. We have created the
start time of function. We need to call this. As
soon as our activity opens. Here at the beginning
itself, we need to call. Let's click on that.
Click on Start level. Here at the top you can see the time it has been initiated. Next, we'll create
a final scorecard.
13. Final Score Card: And I, we'll create final
scorecard for our quiz. For that. Go to File New. And we'll select Empty Activity. Will name this as correct. Duty. Duty in the center
will displace quarter. And at the bottom
we'll tau two buttons. One needs to retake
and other is finish. Text to you. Let us say match parent type wrap
content. Extra color. Blue, will not give
any ID to this text. We will do the id2 next one. Textview, then wrap content. We need to give
an ID, ID, ID dB. This picture you
should be able to finance bottom to top
off finance quote. This one should be at center. Top, the top of parents. You can see it will also, let us say 22. Bold. Your final squared is we'll increase the
text size. Twenty-six. You've been here. Will apply the
next color, green. This time I'm going
to do for score. And even this one will be bold. Now we'll create to what
ads. They can finish. Button. The 15050, bottom to bottom,
left to left off. Martin 20. And even for the first big margin, bottom, margin, bottom. Secondly, we'll create
another button. Distribute to write
off VPN finish. And here takes this finish. We'll create a fence for
text view and two buttons. Whenever we finish our quiz, we need to pass the score and also we need to
pass the 11 name. So re-create score. String level named
Ted Cruz at 2D. So you can see whenever
index equal to nine, we are finishing the
quiz and even matter. But now at that time
it is completed, we are finishing the quiz, will create a new function
and let us finish quiz. Finish quiz. This. We need to call
the score activity. We need to pass the score
and level name. Dot. First one is quarter. Second one should win
Level name, intent dot. To finish, finish, finish quiz. We need to do the same. Even when the timer
is completed. Finish quiz. We need to go into
scored activity. So we need to set
this coordinate score equals to get intent. Variable name is score and
default value. We'll do 0. Similarly, level name
equals get intent. Level name. We need to create a fence
for DB. Final score. Said the finance
finance code. Set. Score, dot set.
Un-click listener. Whenever we click on the deck, we need to restart the quiz. Intent, because intent dot texture, level named, level name. Finish. Whenever we click on
finish on the listener, we need to finish the activity. Finish here. Before clicking on Run. We need to convert this
integer variable to string. Inside setText will simply
use string dot value of. Since we cannot use integer
directly instead takes two, you will use string
dot value of. Let us click on Nancy. Now click on Start. Select 11 will answer a couple of questions and then
we'll skip the remaining. You can see here your final squared is, and
this is the score. If we click on retake, the quiz should start again. You can see here. You
can see here again, you'll find that squared is one. So this time we'll
click on Finish. Now we'll create
chi-squared for each level.
14. High Score for Each Level: Now we'll be creating high
score for each level, will be using
shared preferences. Go to Quiz activity, and here we'll create
shared printers. Let us say S will also
create an editor. Will say Edit preference. Now, we need to set value
into this shape or fence, which is called whenever
we finish the activity, we have created a
function for it. Instead, finish quiz before
starting the score activity, when it is set the score
to Shared Preference. Dot will use the name level
name itself for score, and value should be scored. Dot applied. Now we need to access this inside of
our level activity. So we'll go to level activity. Activity underscore level below each button will
create a text view. Level one score. We need to place it at center, left to left to right off. Right off the bottom of btn level one will create a view which
should be matched bit. And let us say we need to set background black, u1. This view should be below
the level ones code. You can see here we
have 111 text view. This button should be below
this line, which is view. This pattern top to
bottom of view one. Copy this text view and view. This one should be
leveled to score. It should be below
BBN level to this one should be it should be
below the level to score. Similarly, median three
should be below view to. This one will be 113 squared, which would be beloved
btn level three. This one will be Bu
three. Level three score. Getting Ted Cruz activity, we cannot apply the
score directly. First, we need to check whether the current score is higher than the
previous code or not. Score greater than shared with friends started and get
integer will be level name. Default value of 0. If the current squared is
greater than previous code, then only will enter the
value into shared preference. Now inside level activity, we need to access the
shared preference will also create a defense
for TextView. First, we'll create
shared preference. We need to access the
shared reference here. Speed if I speed and
get SharedPreferences. More private. We need to set
high score for each level. Level one score, dot set. Text. Highscore will create
three integer variables. And score LTE. Support. L1 equals, let's put
f dot n level name. Level one, default value is 0. Highscore. Now let us click on click on Start here, but each level we are getting high-school. So now we'll start. Here. We are unable
to see the score, will reopen the level activity. You can see highscore four will reload the level activity
whenever we are clicking finish on the scorecard
will use Andres chart. On this chart will
simply use the recreate, which will recreate
the current activity. Let us click on Run. So click on Start here,
select the level. So here we need to get
a score less than four. Since previously
we have got four. We'll leave it as one. You can see here your final
score is one. Finish. Highscore for. Now we'll click. This time, we'll get a score
greater than four. You can see a squared is five. Click on Finish. You can
see here highscore is five.
15. Questions in Random Order: And now we will split the
quotients in random order. For that, we'll create
an ArrayList list this time of integer type. Integer at random questions
will use a for loop. So I consider less
than I plus plus, since our index starts with 0. Random question dot. Once we added the value
into random equation. So we need to shuffle
the header list. For that, we'll use collections. Dot shuffle. We need to Shaphan the
random question list. Will not get the number
in an ascending order, but we'll get in a random model. We need to go to
create caution. Here. Instead of using GET index, we need to use and get that
Adam cushion dot index. Now let us click on Run
and you can see here, first question is different
than the one we haven't database. Click on Next. We are getting quotients
in a random order.
16. Action Bar Title: A novel activity quiz today
and corrective action, but title, we'll
set the home button so we'll close XML files. So first we look
one level activity, and here after set content
view will use and get, get some protection button
that will take title. Since this is the
level activity will say Select, select 11. Now we need to set Home button, get support, action bar. Whole mess up enabled. Whenever we click
on Home button, we need to finish the activity. Will go to bottom on
options, items selected. Windows which encase switch
item dot, get item ID. Case needs to be dot dot id dot foam, foam
maternal blood. To place this return
statement at the bottom. We'll do the same for
score activity title and this one final score. Even when we best
one back button, we need to finish the
activity on backrest. Finish. So even for the
level activity on backrest finish, we'll copy this on
options items selected. Now for Quiz activity
will create set title. This will take quiz. Next. Set display formats
up and able to true here. We have already
given on backrest. So you can see on bad press, Cancel Tiber and
finish on options. Items are afraid
we'll do the same. Now. Let us click on Run. Now click on Stat. You can see at the top we have a back button and the
text is select level. Now come back button, you are going to main activity. So click on Start,
select a level. If we click on back here, we are again going back
to level activity. So select level. Even for score. If we click on Home button, we are going to level activity.
17. Exit Button: Now we'll create an
Exit button for that. Go to main activity,
and activity main will close all
remaining activities. And here we'll copy this button. Btn exit. For both the buttons will use by asthma
or vertical bias. Constraint vertical by
us and let us say 0.4. Now you can see Start
button has moved up a bit. We'll say 0.45. And for the exit button
will use vertical by us 0.5 for it. Btn exit, btn exit. And similarly, btn exit equals
V rarely dot and btn exit. Whenever we pick
convenient exit, we need to close our app. Btn exit dot. Now, whenever we
click on Exit button, we need to close our app. For that, we'll create
an alert dialog. Dot builder. New dialogue. We need to give the
contexts main activity. Builder dot. Do you want to exit? We need to have two
buttons, yes and no. When we click on Yes,
that should close. And when we click on, the dialogue should
be dismissed. Builder dot set pause to
button. Let us say yes. We need to set an
onClickListener. Finish. Definitely
finish up entity will close all the
open activities. Builder dot. Now we need to
set the negative button, negative button.
We'll send null. When we click on, the
dialogue should be closed. So dialogue interface
and don't dismiss. Finally, we need to
show this dialog. Dot, dot show. We need to repeat the
same when we press on back button as well on backrest, and we'll copy the same. Let us click on tenancy. So now first, we'll
click on back button. Okay, so we'll demo
Super on that pressed. Now, we'll click on
back button first. Back here you have a dialogue. Do you want to accept
when you click on the dialog is dismissed. Now, now we'll click on Yes. That is closed. Will open the app again. Now we'll click on Exit button. Here you have dialogue.
They want to exit. No. No, we'll click on Yes. You can see the app is gross. Whenever we click on
Yes, that closes.
18. Conclusion: Banks were completing
this class. Stay tuned for more such classes and please do complete
the project as well.