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
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'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.
I am currently working on a program that preforms techniques such as image segmentation along with a few others. However I have the task ahead of me of filling a segmented area (this will be a blank area) based on its surrounding pixels.
This is a lot like what photoshop likes to call content aware fill, however me being only one person am wondering the best way I could approach this type task. Also how I should start to think about getting something, obviously not as technical and robust, but similar in some sense to work.
I am not currently aware of any classes that may help with something like this but any help on this would be greatly appreciated.
You are after Inpainting. There are many ways to do it, and an Inpainting survey by Bertalmío, Caselles, Masnou, Sapiro - 2011, presents lots of results and references about them.
Around here you will also find sample results using the technique, for instance at https://stackoverflow.com/a/13666082/1832154 you will see one together with http://www.cc.gatech.edu/~sooraj/inpainting/ that gives a complete implementation. At https://stackoverflow.com/a/14295915/1832154 you can see another sample result, together with a simplistic reference to a different inpainting method.
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.