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.
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 have a program that runs on multiple computers. The program connects to a server where it gets all of its data from. There's a JPanel which lists names from a table in my postgresql database. As of now, the only way to refresh the panel is with a button press. I want the panel to update on its own when there is a change in the database so if one user adds a name, the other users will be able to see the change right away. Is there a way to broadcast a message to all users that are connected to the server so that their panel can refresh?
As soon as you want to do something like this you enter the world of multiple threads and all kinds of havock. Your question does not really have anything to do with databases, you merely want to send a message to all others using the application to update a component when they need to, keep your concerns separate. Now then you need to ask some questions like are the users all on the same network? Then you can get away with a simple chat client for java, there are heaps of them out there. But think about it, do you really need this requirement? Can't you just update the table say every 10 seconds? Or every 5 seconds? The difference in the difficulty of the implementation is substantial but the result I would say would be very similiar, unnoticable to the user even. But maybe you just want to learn stuff, then maybe you think you should add another table in sql with one entry which records the time the user table was updated which you can check and will be more optimal than the other. But this is considered bad practice, do you care? Same with sql statements to check when a table was edited last from what I have seen on the net, but should we always apply best practices, the application will still get across the line.
Maybe your update button is not looking so bad after all.
But users complain about that sort of crap and you can't explain this stuff to every user. My suggestion would be to have a configurable update that runs every how ever many seconds you tell it to. You will have to look up stuff about multi-threading though but shouldn't be too horrible.
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.
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.
I'm a new android programmer so pardon me for the basic question, I already found a valid answer but to be more efficient and use a better method I want to ask on the forum.
I want to place about 30 labels on one page. These might contain about 1-2sentences, what is the most efficient way to scroll through these without making them clickable like a button.
Its also better if I can make this in java, right? Because I could use an array to store the different sentences.
Thanks, to all.
The ListView does exactly what you want in a memory efficient way.
See more information on it here