Hey I'm writing a quiz application for android. Some of the questions asked require just true or false, and some you need to pick from 4 possible options. I've implemented an intereface with 4 radiobuttons and got that to work fine.
I was just wondering what the best way would be to adjust the number of radiobuttons depending on the question type? I've added in an extra field in my question object to state the number of possible answer choices, but i'm unsure how to use this in my program. Any pointers would be appreciated!
At the moment i'm using a textswitcher to update the question asked when I click next and was wondering whether I could use an imageswitcher to make the desired change with the radiobuttons?
ADDITIONALLY - I was thinking about how I could update the labels on the radiobuttons to the possible choices instead of simply A, B, C etc. just to make it look nicer.
You can try these 2
http://developer.android.com/reference/android/view/View.html#setVisibility%28int%29
http://developer.android.com/reference/android/widget/TextView.html#setText%28java.lang.CharSequence%29
Related
I'm relatively new to Android and wanted to practice using it. How do I pass integers in the app? I wanted to build a little combat game where I have a set skill point of 20 and wanted to pass these points to certain attributes. I don't think I can do it through a TextView since hard coding is bad. So essentially my main question is, do I use it through EditText? If so, how? Below is a picture of what I'm trying to achieve.
Thanks a lot for your time.
https://i.stack.imgur.com/i7PNh.png
I don't understand what do you exactly want, but :
TextView is a widget to display a string (or any value converted to string)
EditText is a widget to enter a value
I'm new to both android and java but have been taking some beginner courses on Udacity and reading tutorials. I am looking to create an questionnaire app with about 15 questions total. One question per page, changes when next button clicked. The questions will have different content and number of answers. I know how to create radiogroups and Radiobuttons. Is it stupid to create an activity/layout for each question? I've invested many hours reading and trying to find ways to do this by using only 1 layout with no luck.
Thanks in advance!
Chris
What you need is a ViewPager.
Read about Fragments & ViewPager here:
https://developer.android.com/training/animation/screen-slide.html
If content of different Activities or Fragments is equal in terms of layout, or almost equal, the DRY principle applies (Don't repeat yourself), never copy paste layouts just do have different .xml files.
I am working on a simple Java applet multiple choice quiz that will display a question with three choices. I am pulling the questions and answers from a text file and want to loop through the questions as the user answers them. So every time the user hits 'Submit' the program will check the answer then update the labels with a new question. My question is how do I get the loop to wait on the answer? Should I put all of the code in the button event handler? I thought about Cardlayout, but it seemed inefficient. I don't really have any code yet; I'm still in the planning stage. Thanks!
I would suggest:
First of all regarding, "My question is how do I get the loop to wait on the answer?", I wouldn't even use a for-loop or any similar loop to solve this.
I would create a non-GUI class to hold each question, the possible answers and the correct answer. Consider calling it Question. It would have a String field for the question itself, a List<String> for possible answers, and either another String for the correct answer, or it could hold an int for the index to the correct answer, or even have the correct answer always be the first one, and be sure to randomize the display of answers.
Create an ArrayList of this class, ArrayList<Question>.
Read in the file all at once, filling your ArrayList.
Give your main GUI class an int index variable for iterating through this ArrayList.
When a submit button is pressed, increment your index and get the next item in the List (if not at the size limit of the List).
Consider creating a JPanel class for displaying each question and the possible answers, perhaps called QuestionPanel.
You can either create one display object and swap out the text of your question JLabel and the text of your JRadioButtons. This works nicely if all questions have the same number of possible answers.
Or you could create multiple QuestionPanels, and swap them via CardLayout.
There's nothing "inefficient" about a CardLayout. I have no idea what you're talking about here. Care to elaborate what is inefficient about it, and just what you mean by the term "inefficient"?
I am kind of curious on how would you manage to replace a certain picture on a Grid of rows=4 and columns = 4. Let say if I had 4 images and one of them being blank, how would go on about choosing 1 random images and enabling it to be placed on any row[] and col[].
would i need to do a Boolean logic with double nested for loops?
This is just out of curiosity due to a question a saw here online, I tried attempting it and failed lol. Thanks for your time.
I would like to create a quiz for my Java GUI.
I'd like it to display a question on one page, then have a next button which takes the user to another page telling them if that question was correct or not, and if it is correct they can move on to the next question (by clicking another next button) and if they got it wrong, have to go back and answer it again. However I have no clue how to do this!!
So far I have a simple GUI with a welcome page and tabs down the side, one of which includes a quiz. Would it be a better idea to create the quiz in Flash or something and then embed it into my Java application? Or just do the whole thing in Java? I'm really new to java so I'm not at all sure what to do, any help would be greatly appreciated!
Thanks
It would be best to use just Java. Consider using CardLayout with your GUI to allow swapping questions, or else you can create and modify key components on the fly such as the text displayed by JLabels and JRadioButtons.
Key though before considering any GUI structures is to first create solid OOPS based non GUI classes to handle your questions. For instance, you may want classes for:
Question class that holds a question String, a List of possible answer Strings, a correct answer String. This class can randomly order the incorrect and correct answers, can have a method for checking if the answer selected is correct.
A Test class that holds a collection of questions, that can present questions in random order, that can hold the score obtained.
A QuestionReaderWriter class that can read and write questions to a text file (you definitely do not want to hard-code the question text).
For this type of app it would be best to use the language you are more familiar with.
Since this is just a simple display this then do that there really is nothing very difficult about it.
Personal, I would lean towards Flash as the flash IDE is drag and drop and an experienced flash guru could make this in a few hours. Flash IDE is geared towards this.