I'm making a quiz application on my android phone, and I am struggling with a problem for a long time now, cause I don't know how to continue. The goal of my quiz-app is to let the user listen to a sound and guess what's the name of it. So you have to type your answer in a text box. If you type the wrong answer you can try it again. If you type the right answer the app must remember that you typed the right answer. So if you finished a question and you will later return to that question page, you will see the right answer you typed.
My application can check the answer you typed, but my question is do you have to make a whole database to let the app remember your answer? And is that possible on an application?
I hope someone can help me with my problem, cause I'm not that familiar with java and making apps...
You can easily use the SharedPreferences for this.
Just save a boolean to mark the question as answered.
Example:
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
preferences.edit().putBoolean("Question_ID", true).commit();
http://developer.android.com/reference/android/content/SharedPreferences.Editor.html
You have the following options for storage on Android: http://developer.android.com/guide/topics/data/data-storage.html
If you have a large amount of quiz questions then it is no question that you should use SQLite.
However, if you have a smaller number of questions, then storing data as CSV into a file or using SharedPreferences might be a minimum viable solution to get you on your way to a functional app.
http://developer.android.com/guide/topics/data/data-storage.html
You can use a simple file, shared preferences, or a database. Read the page linked above. It has everything you need including sample code and great explanations.
If your questions are ordered - and they should be, even if you're randomly presenting them, since you read them from some stream or have them in some array when your app starts - then the user's answers can take this same order, and your program's question of "did the user get this right?" (as well as many other useful questions that quizzing software might ask of itself) is answered this simply: what # question is this, internally? Oh, it's 42. So is userGotItRight[42] true or false?
userGotItRight[] is a boolean array, something you can effortlessly persist in a single SharedPreference.
You don't need SQL. You sure don't need a 1:1 map of questions to SharedPreference keys. As your program evolves you can store an evolved serializable object array instead of a boolean array, or you might have a preference per question bank.
Related
I have been given the task to make a text based game and I am opting to go with a dating sim. I have all the dialogue written out but I am stuck on where I would store the dialogue. At first I thought of just making a lot of if statement ex( if you pick this option it takes you to this) but this seems to be really inefficient. So I dont know whether it would be better to have them in an array or array list and just go to that specific place in that array. Sorry if that was confusing that was some background I guess im asking what is the best way to store strings in a game revolving around conversations.
Your question is too vague but of course, other people before has been working on it.
A good starting point (with lot of references) could be, "Gameplay Design Patterns for Game Dialogues" Jenny Brusk and Staffan Björk
On the other hand, Dialog Trees (and here and here) is a way to store dialogs but can work or not for your specific needs.
So I'm currently making a quiz app in Android and am nearing the end. I'm able to shuffle the questions and each one's respective questions. Because of the randomness each time the activity is selected, I'm not sure of a clear way to go about moving between questions.
The only way I can think of at the moment (and it seems like the least intuitive method) is to create an activity for each question and insert the appropriate array number in each, ie. enter variables for QUESTION = question[4].questionString, ANSWER_ONE = question[4].answerString[0], ANSWER_TWO = question[4].answerString[1]...etc. then for the next one insert the same but for [5], and so on. Each activity represents one block of the 'question' array. I feel like there is, or should be, a more practical way to implement this.
I've looked slightly into fragments and viewpager, but I'm not too familiar with those (and any other options) to be able to determine which would be the ideal (or even practical) way to go. So what options do I have? And are any options clearly the best?
Why not just update the UI to the new question. That way you'd have just one activity for handling all the questions.
Every time the user clicks an answer or chooses next question button, you could update the UI to show new question.
I have been working on an app that can save your passwords for you. I would like it to work similarly to a contacts application. For example, I want to have a screen that displays all the names of the passwords entered (like the names of your contacts), then when you click on the name, it takes you to a screen with all the information you previously entered on it (like the phone numbers/email addresses that would be in your contacts). I also would like a way to edit this information. I have been searching for almost 2 weeks now and have found nothing to help me. If someone could simply point me in the right direction, or tell me what this way of saving information would be called so I can research it, it would be GREATLY appreciated. If possible, could any answers be explained well enough that a fairly new developer could understand them.
I think you need a ListView and some Adapter to show the name of the password, and when you click one of them, you create an Intent which leads you to a new Activity which show the associated details. In the detail Activity you can do some editing job and save them to database or ContentProvider.
If I am right, I think you need to follow the tutorial of Android development to learn more about Android system.
I have been working on an app and have encountered some limitations relating to my lack of experience in Java IO and data persistence. Basically I need to store information on a few Spinner objects. So far I have saved information on each Spinner into a text file using the format of:
//Blank Line
Name //the first drop-down entry of the spinner
Type //an enum value
Entries //a semicolon-separated list of the drop-down entry String values
//Blank line
And then, assuming this rigid syntax is followed always, I've extracted this information from the saved .txt whenever the app is started. But things such as editing these entries and working with certain aspects of the Scanner have been an absolute nightmare. If anything is off by even one line or space of blankness BAM! everything is ruined. There must be a better way to store information for easy access, something with some search-eability, something that won't be erased the moment the app closes and that isn't completely laxed in its layout to the extent that the most minor of changes destroys everything.
Any recommendations for how to save a simple String, a simple int, and an array of String outside the app? I am looking for a recommendation from an experienced developer here. I have seen the storage options, but am unsure which would be best for just a few simple things. Everything I need could be represented in a 3 X n table wherein n is the number of spinners.
Since your requirements are so minimal, I think the shared preferences approach is probably the best option. If your requirements were more complicated, then a using a database would start to make more sense.
Using shared preferences for simple data like yours really is as simple as the example shown on the storage options page.
My assignment is to create a simple Quiz app for Android. I am NOT looking for the code for this.. I am simply looking for someone to possibly lay out how to get started with this (pseudo-code ish).
The program is suppose to display one term and four definitions; one of them being the correct one. Once the user selects which one they think it is, the program will tell the user if it was correct / incorrect using a toast message.
Specs:
The terms need to be randomly selected, and only displayed once per run. However the definition needs to stay in the pool of definitions for other questions.
Definitions randomally selected (except the right one)
Program ends if it runs out of terms to display
Needs to use an ArrayList to hold collections of items, and a HashMap to hold name-value pairs.
Must use Androids logging mechanism to log error messages (via try/catch statements).
If you can help me out by guiding me in the right direction, that would be great :) Thanks!
I would (as always in object-oriented languages) start by mapping your problem to real-live objects. In your case, there would be two:
A Question-class which holds four answers, the question and offers a method to check if the given answer was correct.
An Answer-class which holds a single answer and whether it's correct or not.
As for your storage question, I wouldn't use a HashMap at all. Store the Question-instances in an ArrayList and use a Random.nextInt()-method to get a random question from your list.
In your Question-class, you would store all possible answers in another ArrayList. To randomize the order in which the answers are presented, you can use the Collections.shuffle()-method.
For the presenting part, have your Question-class return the question (string) and the four answers (strings) and put the into your widgets. To identify the answer given, you can use the Answer-instance (using the array-index is easier, but it is more error prone).
To check if the right answer was given, query your Question-classes isCorrect(Answer)-method and check if the given instance in the internal ArrayList is marked as the correct one.