Creating a Quiz Android App

This is a tutorial on creating a quiz in Android. After this tutorial you will be able to create your own Android App with your own quiz.
Follow the instructions given below to learn how to create a quiz app in Android.

1. Download Sketchware App for Android devices.

2. Open Sketchware and start a new project. Enter the app name and other details as per your wishes and click save.

3. Now in the View area (main.xml), insert a Scroll(V) and inside that a Linear(V). Set the width of both the Layouts to match parent and set the padding of Scroll(V) to 0. Also set the background color of Linear(V) to green or a color of your choice, and gravity of Linear(V) to center_horizontal, center_vertical.
4. Now insert 4 button widgets (depends on your requirement), one each for each of the quiz. Each quiz can have several questions. Rename the buttons as Quiz1, Quiz2, Quiz3 and Quiz4 respectively. Now for each of the buttons: increase font size to 18, set margin of each to 8, set text style to bold, and set background color to white.
5. Click on main.xml and add four more views. Name them as quiz1, quiz2, quiz3, and quiz4 respectively​.
6. Move to Logic area. Add a new Intent component and name it option (or anything else you want).
7. Next, in Button:button1 onClick event use following component blocks to set screen to quiz1:
Intent option setScreen Quiz1Activity
StartActivity option
Use same logic for other buttons to set screen to Quiz2, Quiz3, and Quiz4.

8. Now move to View area and select quiz1.xml. Inset a Linear(V) (linear1). Set it's width to match_parent and set it's background color to green.

Inside this insert a Linear(H) (linear2), a Linear(V) (linear3; set layout_height of this layout to wrap_content), and another Linear(V) (linear4). Set width of all these linears to match_parent.

9. Increase weight of linear2, linear3 and linear4 to 1, 2, and 2 respectively. Also for the three linears, set margin to 8, and set background color to white.
10. Insert a Textview (textview1) in linear2. Make it's width match_parent, text_size 18, text_style bold, and lines 3.

In linear3, insert four Linear(H) and inside each of these four linears insert a checkbox and a Textview. Set text of each checkbox to empty. For Textview change text_size to 18 and text_style to bold. Also insert a button (button1​) in linear3 and change it's layout_gravity to right, and text to 'Next' or '>>'.

In linear4 Insert three linears and a textview in each linear. In second and third textview write correct answers to all the questions. Insert a button (button2) below that, change it's layout_gravity to center_horizontal and name it as Menu.
11. Now move to Logic area of quiz1 (Quiz1Activity.java).

Create a new Intent component and name it intent.

Go to onCreate event. Add three new blocks and name them as Start, Questions, and Answers. Also add three new number variables namely ques, ans, and score. Add Start block in onCreate event.


12. Add five new events, one each for the four checkbox onClick, and one for textview1 onClick.

13. In Start defineFunction use following blocks:
Set ques to 1
Set score to 0
textview1 setEnable true
textview1 setText Click here to start Quiz
linear2 setVisible VISIBLE
linear3 setVisible GONE
linear4 setVisible GONE

14. In Questions defineFunction use if then blocks and write all the questions and options for each of the questions, as shown in the image below.
If ques = 1 then
textview1 setText Your first question?
textview2 setText option 1
textview3 setText option 2
textview4 setText option 3
textview5 setText option 4

Add all the questions and their options one by one for each value of ques. I added four questions. After adding all questions use the block as shown below.
If ques = 5 then
linear2 setVisible GONE
linear3 setVisible GONE
linear4 setVisible VISIBLE
textview6 setText join Your Score is: and toString score without decimal


15. In Answers defineFunction​ set variable ans to correct option for each question.
If ques = 1 then
set ans to 1
If ques = 2 then
set ans to 3
If ques = 3 then
set ans to 1
If ques = 4 then
set ans to 4

16. In checkbox1​ onClick, setChecked false all other checkbox. Do this for each of the checkbox onClick.
17. In textview1 onClick, use following blocks:
textview1 setEnable false
linear3 setVisible VISIBLE
Questions
Answers
18. In button1 (which is our Next button) onClick use following blocks:
If checkbox1 ​getChecked then
If ans = 1 then
score increase 1
ques increase 1
checkbox1 setChecked false
Questions
Answers

Use these blocks for each of the checkbox.
19. On button​2 onClick, use setScreen block to move to MainActivity.
Intent intent setScreen MainActivity
StartActivityintent
20. Now use same codes to create more quizzes, in this case Quiz2, Quiz3, and Quiz4.

21. Save and run the App. You'll find your first Android quiz app is ready and working.

Here is a video to make it easier for you:

Comments

  1. This comment has been removed by the author.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Hi, I want to create a app through Sketchware. Can I create a app which open a new screen by sliding (by sliding the screen with finger) just like whatsapp. Please look on the attachment.

    https://goo.gl/KyLdC7

    ReplyDelete
    Replies
    1. No it cannot be done in Sketchware. You can change screens by clicking link on the top status bar, and make that sliding. Or leave a space below to add a Seekbar, and change screen by sliding on Seekbar.

      Delete
    2. will you please make a video whatever you say and please send me the video.

      Delete
  4. Can we create a gallery app?

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
  7. Ciao, ho capito che sul video tutorial di Youtube avevo aggiunto 11 domande e non livelli come io credevo, molto meglio!
    Ho un problema nell'inserimento di layout e widget in questo
    caso, ho il link:

    https://drive.google.com/file/d/1MjbcEnWFbrWM-EZS04VTdT4U0zK8JMP4/view?usp=drivesdk

    Grazie di cuore per l'aiuto!

    ReplyDelete
    Replies
    1. You have to use a ScrollView and inside that a linear V, and in it put everything else.

      Check start 1 minute of this video: https://youtu.be/QQTZCemJ758

      Delete
  8. Perfetto, ora va meglio grazie mille

    ReplyDelete
  9. Sir please help to app create in sketchware (How To items added and how to modify to app published after..) Plz help to my small request

    ReplyDelete
  10. Hello. Many thanks for the videos tutorials on youtube. Started working on maths quiz app already but i've got little challenge. I added 4 questions to the 4 as described in your video but despite i answered all the questions correctly my score still shows 6 instead of 8. What do i do please, as i intend to add about 100 more. Kindly assist please.

    ReplyDelete
  11. I've follow the steps to create a quiz but it stacked in question, it won't run..there is should be some command block wrong placed.. Can you post a clear step in pictures? Thanks a lot

    ReplyDelete
  12. I think it has a premium version. So, I want to modify it with the lucky patcher application to get premium features for free. Can I do it?

    ReplyDelete

Post a Comment

Popular posts from this blog

A Flash Light App in Sketchware

Create Music Player app in Sketchware

In Sketchware: How to create a calculator for any simple formula?

Simple car racing android game in Sketchware

Firebase auth in Sketchware for Login Activity