Lesson16 Android - Multiple Choice Quiz : save result in SharedPreferences

Поділитися
Вставка
  • Опубліковано 16 гру 2024

КОМЕНТАРІ • 207

  • @krishnabawane7104
    @krishnabawane7104 5 років тому +2

    Thank you so much, sir! Sir, I m creating the mini project for my college everything was done but I want to show the result in the last page. By watching your video I get my result.
    Thank You, sir.

  • @princessserah3638
    @princessserah3638 5 років тому +1

    This is an excellent video. Thank you for sharing it. I have learnt a great deal.

  • @YT-ko9gd
    @YT-ko9gd 7 років тому +1

    Огромное спасибо за урок и за доступ к коду! То, что мне надо

  • @rakeshsenwar2778
    @rakeshsenwar2778 7 років тому

    Best Android Tutorials on youtube!

  • @jungabrielcodog2783
    @jungabrielcodog2783 7 років тому +2

    "private void updateScore (int point){" it says that parameter point is never used? can you help me with this? :( pls I barely need it :(

  • @AshishJayan
    @AshishJayan 7 років тому

    Thanks for the informative video Vlad.

  • @payambassi8784
    @payambassi8784 6 років тому +1

    Hi Volodymyr Voytenko, thank you for your amazing video, I was wondering if you could show or at least suggest how to go a bout creating a method whereby the questions that have been answered correctly do not come up again until for example all questions have been answered correctly where they all get reset, and get updated as normal.

    • @VladVoytenko
      @VladVoytenko  6 років тому +1

      I do not think it's hard to update the current code for the task you suggested. You work with array list of questions, and its' easy to manage - dynamically delete items, or add.

    • @payambassi8784
      @payambassi8784 6 років тому

      I got it, Thanks.

    • @payambassi8784
      @payambassi8784 6 років тому

      Hi, Volodymyr Voytenko, I have managed to get this method done with an Arraylist and it works great, however the downside is that if you close the app, the Arraylist data gets cleared. Please can you recommend something that I can replace the Arraylist with so that the data is not lost once the app is closed.

  • @gihonprayogo7122
    @gihonprayogo7122 7 років тому

    Hi Vlad, I've followed the tutorial you gave, but my program is not running well. When i test it. The buttons does not work. it remains on the first question.

    • @VladVoytenko
      @VladVoytenko  7 років тому

      hi Gihon, thanks a lot for your question! Well, if buttons don't work and there is no any other errors, you have to check if the method - a click listener - attached to those buttons. It's easy to fix - just open your layout xml and check it. Hope it will help!

    • @gihonprayogo7122
      @gihonprayogo7122 7 років тому +1

      Vlad Voytenko It's true. that the onClick method in xml has not been attached with onClick in Quiz Activity Java. Thanks a lot Vlad!

    • @VladVoytenko
      @VladVoytenko  7 років тому +1

      Well done! Good job, Gihon! :-)

    • @hussainalbader3326
      @hussainalbader3326 7 років тому

      can you show me how you did it please
      just one example

    • @gihonprayogo7122
      @gihonprayogo7122 7 років тому

      Hussain Albader Type android:onClick="onClick" on each button in the xml. In order for the onClick method in java to connect to xml

  • @SuperHiggybear
    @SuperHiggybear 7 років тому +2

    Hi vlad I am just wondering how do you randomise the questions without SQLite database? I see your comments underneath saying you can randomise it but I don't know where to put he code in?

    • @VladVoytenko
      @VladVoytenko  7 років тому +1

      hi David, randomization is done in Lesson18, I am using simple Java randomization in a program, this is not related to Android at all.

    • @SuperHiggybear
      @SuperHiggybear 7 років тому +1

      Vlad Voytenko so If i take that snippet of randomisation code from lesson 18 and put it in my quiz it should make the questions come up randomly?

    • @VladVoytenko
      @VladVoytenko  7 років тому +1

      pretty much, David! you randomize an array of question in your program - this is it!

    • @SuperHiggybear
      @SuperHiggybear 7 років тому

      Hi Vlad, so basically you would just need to put this in lesson 16 without using the sqlite database to make the questions random then?
      import java.util.ArrayList;
      import java.util.List;
      public class QuestionBank {
      // declare list of Question objects
      List list = new ArrayList();
      // method returns number of questions in list
      public int getLength(){
      return list.size();
      }
      // method returns question from list based on list index
      public String getQuestion(int a) {
      return list.get(a).getQuestion();
      }
      // method return a single multiple choice item for question based on list index,
      // based on number of multiple choice item in the list - 1, 2, 3 or 4
      // as an argument
      public String getChoice(int index, int num) {
      return list.get(index).getChoice(num-1);
      }
      // method returns correct answer for the question based on list index
      public String getCorrectAnswer(int a) {
      return list.get(a).getAnswer();
      }

    • @VladVoytenko
      @VladVoytenko  7 років тому

      You just need to shuffle list:
      Collections.shuffle(list);

  • @dev.spectures
    @dev.spectures 7 років тому

    force close after minute 12:20 error =void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference How to solve it ??

    • @VladVoytenko
      @VladVoytenko  7 років тому

      It looks like you may have a typo error for the variable(s).... Please, check carefully name of the TextView variables in this file, plus names of their widgets.

    • @dev.spectures
      @dev.spectures 7 років тому

      Hello sir! Whch name must I insert after: int *which variable?* = intent.getIntExtra("score",0);
      txtScore.setText("Your score"+ *which variable?*);

    • @dev.spectures
      @dev.spectures 7 років тому

      beause when I delete txtScore.setText("Your Score " + score) i start not with the main activity but the second activity open itself (HighestScoreActivity)

    • @dev.spectures
      @dev.spectures 7 років тому

      Please help me

  • @Welruuu
    @Welruuu 7 років тому

    Hi vlad, how do you randomize the question and restrict it to stop the game at 10 questions only If you have more than 10 questions?

    • @VladVoytenko
      @VladVoytenko  7 років тому

      As far as I remember, we already discussed it in the past.... Please, check old messages!

    • @Welruuu
      @Welruuu 7 років тому

      I can't seem to find it. What i want to do is have a set of questions randomly chosen from the array then stops if all of the questions in the array are used.

  • @dev.spectures
    @dev.spectures 7 років тому

    Hello! What in the code do I have to change if I want that the score will appear also when a answer is false?

  • @gadrian1153
    @gadrian1153 7 років тому +1

    Hey sir, can you help me please? I have 2 checkbox with yes and with no. Olso I have a button who swich the activities.. I want to know how I can show the rezult from that 2 checkbox on the second activies.

    • @VladVoytenko
      @VladVoytenko  7 років тому

      It is not difficult, Adrian! Please, check a video how to switch between Activities:
      ua-cam.com/video/uMfQv6BaG5A/v-deo.html
      How to press Button and Switch to the next screen ?
      Follow simple steps to find out !

    • @gadrian1153
      @gadrian1153 7 років тому

      No no no, sir ... I know to do this... I want to show on the second activity what I check on the first in checkboxs.

    • @VladVoytenko
      @VladVoytenko  7 років тому

      that's easy for you!

    • @gadrian1153
      @gadrian1153 7 років тому

      I think... But I DONT KNOW how to do that ... Can you help me with this?

    • @VladVoytenko
      @VladVoytenko  7 років тому +1

      I am busy 24/7, sorry not having time to provide full support for all of you

  • @gihonprayogo7122
    @gihonprayogo7122 7 років тому

    Hi master Vlad, I have a problem. When I add 10 questions, in the sixth question my program stops, not update to the next question. I've followed all your tutorials..

    • @VladVoytenko
      @VladVoytenko  7 років тому +1

      Hi Gihon, you problem is not Android-related. Well, if you can reach questions from 1 to 6, but not further, check your code very carefully: you probably have a typo somewhere.

    • @gihonprayogo7122
      @gihonprayogo7122 7 років тому +1

      Thanks Vlad. I've found the problem. Now my program is running well

  • @bismanaeem5337
    @bismanaeem5337 6 років тому

    really really helpful

  • @EZBSgaming
    @EZBSgaming 6 років тому

    Hi, im wondering how do you do get your buttons to work?

    • @VladVoytenko
      @VladVoytenko  6 років тому

      please, check the video again - all buttons work just fine!

    • @VladVoytenko
      @VladVoytenko  6 років тому

      Also, if you need to check Button video tutorial, please check the link below:
      ua-cam.com/video/WN7930A0D_4/v-deo.html

  • @akinfenwakast1551
    @akinfenwakast1551 7 років тому

    I need your help! I have a problem. When i click on one of the options when there is a question, i don't get to the next question and literally nothing happens (no score update, no next question, nothing). Do you know how i can fix this?

    • @VladVoytenko
      @VladVoytenko  7 років тому

      No clue, it works absolutely perfect on my side. Please, check carefully what is missing.

    • @akinfenwakast1551
      @akinfenwakast1551 7 років тому

      I found what was missing, but still thanks for the fast reply! But now i have another problem, if i finish the quiz and i get the screen with try again. If i press the back button on my phone i get the last question again. If i do this a lot and press the correct answer over and over again, i can get 30 points as high score, but i only have 10 questions... Do you know how i can fix this?

    • @akinfenwakast1551
      @akinfenwakast1551 7 років тому

      public class onderwerp1 extends AppCompatActivity {
      @Override
      protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.onderwerp1);
      TextView txtScore = (TextView) findViewById(R.id.textScore);
      TextView txtHighScore = (TextView) findViewById(R.id.txtHighScore);
      // receive the score from last activity by Intent
      Intent intent = getIntent();
      int score = intent.getIntExtra("score", 0);
      // display current score
      txtScore.setText("Your score: " + score + " / 10");
      // use Shared preferences to save the best score
      SharedPreferences mypref = getPreferences(MODE_PRIVATE);
      int highscore = mypref.getInt("highscore", 0);
      if(highscore>= score)
      txtHighScore.setText("High score: "+highscore + " / 10");
      else {
      txtHighScore.setText("New highscore: " + score + " / 10");
      SharedPreferences.Editor editor = mypref.edit();
      editor.putInt("highscore", score);
      editor.commit();
      }
      TextView txtScore2 = (TextView) findViewById(R.id.textScore2);
      TextView txtHighScore2 = (TextView) findViewById(R.id.txtHighScore2);
      Intent intent2 = getIntent();
      int score2 = intent2.getIntExtra("score2", 0);
      txtScore2.setText("Your score: " + score2 + " / 10");
      SharedPreferences mypref2 = getPreferences(MODE_PRIVATE);
      int highscore2 = mypref2.getInt("highscore2", 0);
      if(highscore2>= score2)
      txtHighScore2.setText("High score: "+highscore2 + " / 10");
      else{
      txtHighScore2.setText("New highscore: " + score2 + " / 10");
      SharedPreferences.Editor editor = mypref2.edit();
      editor.putInt("highscore2", score2);
      editor.commit();
      }
      }

    • @akinfenwakast1551
      @akinfenwakast1551 7 років тому

      Can you tell me what the mistake is?

    • @akinfenwakast1551
      @akinfenwakast1551 7 років тому

      Here you have some more information about the app. I am sorry i am asking so many questions, but the problem is here. You have in your tutorial: Your score: 3 and Highscore: 3. I have 2 times a quiz what referes to the same page with try again on it. If i do the second quiz my "Your score" gets updated for quiz 1 and quiz 2. If i do quiz 1, only my first "Your score" gets updated.

  • @isolokwupatrick1559
    @isolokwupatrick1559 6 років тому +2

    NICE TOTURAL ,how about if id like to save the score with players name

    • @VladVoytenko
      @VladVoytenko  6 років тому

      Just add player name to database - and ask user to enter at the beginning. It should not be hard task.

  • @stenisen44
    @stenisen44 6 років тому

    hello, my 'getLength' is red. " if (mquestionnumber

    • @stenis4225
      @stenis4225 6 років тому

      I have the same problem

    • @VladVoytenko
      @VladVoytenko  6 років тому

      it's syntax error, but you didn't provide it ... Check the message and fit the problem

    • @stenisen44
      @stenisen44 6 років тому

      Sorry, I'm new to this coding and java. But the error message is "Cannot resolve method 'getLength()'

    • @VladVoytenko
      @VladVoytenko  6 років тому

      all you need to check definition of the method mquestionlibrary.getLength() in your code, if availbale

  • @ukisar99
    @ukisar99 7 років тому

    I have a question,how can i put images and questions in quiz?

    • @VladVoytenko
      @VladVoytenko  7 років тому

      Why not? It's very easy - just check a Lesson how to add image to the Activity.

    • @ukisar99
      @ukisar99 7 років тому

      Wait,i just can add image to Activity,how to add for specify question?
      P.S.I already know that

    • @VladVoytenko
      @VladVoytenko  7 років тому

      Great! When you change the question every time, you have to load new image.

    • @ukisar99
      @ukisar99 7 років тому

      Then in the quiz bank i have to load the images?

    • @VladVoytenko
      @VladVoytenko  7 років тому

      well, you can prepare images for each question in quiz bank. But you have to load the image when you update the question only.

  • @sahertabassum8249
    @sahertabassum8249 6 років тому +1

    hi sir! From where i can get this cod????

    • @VladVoytenko
      @VladVoytenko  6 років тому

      drive.google.com/open?id=0B-AihUewoOXfYUEzdVFOSzB2RE0

  • @marinolopez3472
    @marinolopez3472 7 років тому +1

    i cannot access the link to your project as it requires permission.

    • @VladVoytenko
      @VladVoytenko  7 років тому +1

      you have to try again...

    • @ray7frey496
      @ray7frey496 7 років тому +1

      maybe just need upgrade the gradle.. that was my little problem..

    • @VladVoytenko
      @VladVoytenko  7 років тому

      yup! Gradle upgrade is required in many cases.

  • @kaloygaming5
    @kaloygaming5 7 років тому

    Why is it that the game stop stop when reach the last question sir .?

    • @VladVoytenko
      @VladVoytenko  7 років тому

      What do you mean by this? when you reach last question, it should show you final score and eventually stop, isn't it?

    • @kaloygaming5
      @kaloygaming5 7 років тому

      yes ..sir
      fortunately sir I already solve it..thanks for the updates sir

    • @VladVoytenko
      @VladVoytenko  7 років тому

      great! thanks a lot for update!

    • @VladVoytenko
      @VladVoytenko  7 років тому

      thanks a lot for your comments! I am glad you solved it!

  • @Fatkhulizza
    @Fatkhulizza 7 років тому

    can you help me for problem. how to make a Random Quiz .?

    • @VladVoytenko
      @VladVoytenko  7 років тому

      We discussed this solution already. Please, check discussion board for lesson 16 and lesson 18!

    • @Fatkhulizza
      @Fatkhulizza 7 років тому

      Thank you very much

  • @andridarmawan1884
    @andridarmawan1884 7 років тому +1

    halo sir.
    how to create a image quiz?
    thanks sir

    • @VladVoytenko
      @VladVoytenko  7 років тому

      hi Andri, we discussed it with Урош below. Please, check his questions and answers and let me know if you need more help!

  • @ajdee3661
    @ajdee3661 7 років тому

    hi, is it possible to share results to other users/devices?

    • @VladVoytenko
      @VladVoytenko  7 років тому

      no, you can't do it for current application - all data are private and visible only to one user at this time

    • @ajdee3661
      @ajdee3661 7 років тому

      you do know how to do it tho,dont you?

    • @VladVoytenko
      @VladVoytenko  7 років тому

      If you need it, you have to write application with Content Provider support to share the same data.

    • @ajdee3661
      @ajdee3661 7 років тому

      Vlad Voytenko would you please help me through the process?

  • @urfriendlyprogrammer3301
    @urfriendlyprogrammer3301 7 років тому

    @Vlad Voytenko is the souce code for free?

  • @AzimuthPH
    @AzimuthPH 7 років тому

    hello, is it possible to highlight the correct answer if you press the wrong answer?

    • @VladVoytenko
      @VladVoytenko  7 років тому +1

      Hello Azimuth, sure, it is possible: once user answer the question, you may highlight the right answer with a different color.

    • @AzimuthPH
      @AzimuthPH 7 років тому

      hope you can show us how if you have time. thanks to this tutorial. this helped me a LOT.

    • @bertmarcos1454
      @bertmarcos1454 7 років тому

      great idea. it would be nice if Mr. Voytenko would teach us how.

    • @bertmarcos1454
      @bertmarcos1454 7 років тому

      looking forward to it sir. pls

    • @VladVoytenko
      @VladVoytenko  7 років тому

      Please, come to our classes, guys - everyone welcome!

  • @marjbanzon5648
    @marjbanzon5648 7 років тому

    hi, in my quiz activity. the "point" in (int point) and the onClick says "Method is never used" . when i tested it, the buttons does not work, it remains on the first question. what could be the problem? this is the onClick:
    private void updateScore(int point){
    mScoreView.setText("" + mScore+"/"+mQuestionLibrary.getLength());
    }
    public void onClick(View view) {
    Button answer = (Button) view;
    if (answer.getText() == mAnswer) {
    mScore = mScore + 1;
    Toast.makeText(quizaActivity.this, "Correct!", Toast.LENGTH_SHORT).show();
    } else
    Toast.makeText(quizaActivity.this, "Wrong!", Toast.LENGTH_SHORT).show();
    updateScore(mScore);
    updateQuestion();
    }
    }

    • @VladVoytenko
      @VladVoytenko  7 років тому

      Marj, you may simply have a typo somewhere in your code... How about to download the project, import it into your workspace ans run?

    • @marjbanzon5648
      @marjbanzon5648 7 років тому +1

      I found the error in my code. Now it is working.
      What should i replace if i want to make an image quiz app? I mean replace the questions with images. Only the question is replaced the multiple choices are the same.

    • @VladVoytenko
      @VladVoytenko  7 років тому

      Marj, you can add picture to current layout to have quiz app with images. You have to work more on a layout level. Please, check another video, Lesson 10_1 :
      ua-cam.com/video/2fFdz108whI/v-deo.html

    • @gihonprayogo7122
      @gihonprayogo7122 7 років тому +1

      Hi Marj, i have the same problem as you, when i tested it, the button does not work, it remains on the first question. how you fix it?

  • @danielananta2742
    @danielananta2742 7 років тому

    How to add another quizz section in to one app?

    • @VladVoytenko
      @VladVoytenko  7 років тому +1

      you have to create multiple quiz Activities in this case, organize them in the list view, and call them from Main Activity.

    • @danielananta2742
      @danielananta2742 7 років тому

      ok i am stuck, i hope you make tutorial video about that,

    • @VladVoytenko
      @VladVoytenko  7 років тому

      Thank you, but I am not sure if we have a lot of people interested.

  • @maisamafshar
    @maisamafshar 7 років тому

    Hey Vlad Votenko,
    I am a new fun!
    Thank you for your tutorials. I have a problem and would be thankful if you help me out with it.
    I don't want to have an on click listener on each button or on my radio buttons, I want the answers and questions be added and calculated through another button, suppose something like " Next Question " button on each page. I tried alot but couldn't figure out. Would you mind coding it for me ?
    thanks ind advance,

    • @VladVoytenko
      @VladVoytenko  7 років тому +1

      Thank you, Maisam! Your suggested version not very different. But it will be a bit harder, since you need to check the logic for each question separately.

    • @maisamafshar
      @maisamafshar 7 років тому

      If you had time please do a video on it or you may send me that snippet of code.
      What do you prefer, saving the records on shared preferences or on Sqlite database ? or it doesnt matter ?

    • @VladVoytenko
      @VladVoytenko  7 років тому

      of course, using database is a better choice. You may check video from Lesson18 regarding this.

  • @asoryu3867
    @asoryu3867 7 років тому

    Can you please give me the code on how can i random the questions please?

    • @VladVoytenko
      @VladVoytenko  7 років тому

      hi Yusor, randomization is done in Lesson18, I am using simple Java randomization in a program, this is not related to Android programming, but only Java.

  • @kaloygaming5
    @kaloygaming5 7 років тому

    do you have a lesson 15 of tutorial of it sir??

    • @VladVoytenko
      @VladVoytenko  7 років тому

      yes, it has lesson 15_1, and lesson 15_2

  • @johnlouie8129
    @johnlouie8129 7 років тому

    good pm. what if i want to randomize my question. thank you.

    • @VladVoytenko
      @VladVoytenko  7 років тому

      Questions randomization can be completed using simple Java techniques, this is not related to Android development. One of the standard way to do this is in Java as follows:
      Random rn = new Random();
      int question = rn.nextInt(10) + 1;
      This will work for generating a question umber from 1 to 10. Make sure you import Random at the top of your code.

    • @johnlouie8129
      @johnlouie8129 7 років тому

      it does not finish the game. it just randomize the questions but it does not finish the game. i have 10 question but its more than 10 when i play it.

    • @johnlouie8129
      @johnlouie8129 7 років тому

      Btw you said the link is in the bottom? Were is the link for this video? thank you so much

    • @VladVoytenko
      @VladVoytenko  7 років тому

      sure, it will play without restrictions - you may need to stop the quiz when you want

    • @VladVoytenko
      @VladVoytenko  7 років тому

      Link for the current version of project is posted under the video.

  • @caldereta101
    @caldereta101 7 років тому

    How many questions can I put in one activity?

    • @VladVoytenko
      @VladVoytenko  7 років тому

      any specific reason behind that ?

    • @caldereta101
      @caldereta101 7 років тому

      Vlad Voytenko im wondering if its possible to do 4 sets of quiz and 100 questions per set using your tutorial video? Or sql is already needed for that? Thanks!

    • @VladVoytenko
      @VladVoytenko  7 років тому

      this video show how to create 1 (one) set for unlimited number of questions.

  • @rosalindamemenzaquispe3226
    @rosalindamemenzaquispe3226 7 років тому

    exelente video amigo , como aria si si deseo salir de juego se guarde el nivel y cuando abro la aplicación empiece a jugar donde le eh dejado-. di si quiero ponerle vidas como hago

  • @mahimachandane9067
    @mahimachandane9067 6 років тому +1

    Thank you

  • @mikelantzelo
    @mikelantzelo 7 років тому +1

    Cannot access the link

  • @1takecover
    @1takecover 7 років тому

    Where Can I find the project code ?

    • @1takecover
      @1takecover 7 років тому

      I have subscribed your channel.

    • @VladVoytenko
      @VladVoytenko  7 років тому

      Please, check your e-mail. Thanks!

  • @shahedr96
    @shahedr96 7 років тому +1

    access please

  • @zilvinasskipitis8016
    @zilvinasskipitis8016 7 років тому

    Hey can u give access to your project ?:)

  • @vetyab_com
    @vetyab_com 5 років тому

    please share the source code

  • @kiester6847
    @kiester6847 5 років тому

    Thank you for this video sir, I had modify this instead of Button I change it to Imageviwe so that choices are images in a array. I have trouble in the section where the system checks if the button click is equal to the right answer and if it is correct the score will add to1. below is my code to that section it has no error but it doesnt execute the if only the else part. I hoe you could help me out, thank you d ill wait for your response plssssss...
    if (answer.equals(mAnswer)){
    mScore = mScore + 1;
    Toast.makeText(QuizActivity.this, "Correct!", Toast.LENGTH_SHORT).show();
    }else
    Toast.makeText(QuizActivity.this, "Wrong!", Toast.LENGTH_SHORT).show();
    // show current total score for the user

  • @azharmohd2811
    @azharmohd2811 7 років тому +1

    Please give me the source code i have subscribed your channel

    • @VladVoytenko
      @VladVoytenko  7 років тому

      Hi Azhar, please click on the link below:
      drive.google.com/file/d/0B-AihUewoOXfYUEzdVFOSzB2RE0/view?usp=sharing

  • @anitchoudhary527
    @anitchoudhary527 7 років тому

    I have not any link after subscribe your channel

    • @anitchoudhary527
      @anitchoudhary527 7 років тому +1

      reply plz

    • @VladVoytenko
      @VladVoytenko  7 років тому

      Project code for Lesson 16:
      drive.google.com/drive/folders/0B-AihUewoOXfZmNmZ1Z3V1JXM0k

  • @Solvatech_service
    @Solvatech_service 7 років тому

    не проще на русском было?)

    • @VladVoytenko
      @VladVoytenko  7 років тому

      нет, не проще - я уже привык к английскому ), во-вторых, англоязычная аудитория намного шире