Single or multiple layouts? - java

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.

Related

how do I attach a description to an imagen in android studio?

first of all I want to thank, because in this community I have found a lot of solutions to my development question. But this time I have a big one. I was looking for an answer to it in google and pdf´s and so on. But it's a complicated question and don't know how exactly ask for it in google. I new in app development. so here I go. I'm trying to do an app that shows the different recipes with photos and description like time that it takes and the difficulty and so.
explanation of the question
Apologize because the childish imagen to explain to you but you know (efficiency).
My two questions are:
1) How may I do to attach a description to an image. I mean, I want that the people can add their own recipes and of course I will make a formulary to this, but how may I do to when the people create the recipe that I suppose that it should be an object of a class, the TextView be attached to the bottom of the image automatically. in resume, that the image and the description with their elements be one unique element. I have tried to encapsulate the image and the text view in one layout, but in this case I don't know how to create a new layout once the app is running. ok the user fill the formulary but how to create a new layout on the run. I don't know how to solve this.
2) How may I do to change in the description of the image the quantity of red tomatoes. I mean. if the recipe have 3 in difficulty, 3 of 5, this is settled by the user, but how I do to show 3 red tomatoes of 5 and the other showed in gray?
I know you may say "another Newby" but I have realized that I love programming and in El Salvador (Central America) there´s almost any information about this subject. Again, thanks a lot.
one way to achieve that is by using Recycler view. and every time a user adds an item. you can add it to the list and the system will draw a new item for you.
check this tutorial
let me know if this helps or you need more explanation

Get userinput from edittext on a fragment

I wanna start out by saying that im just starting to learn android development(and programming) just so you guys know that im not an expert or anything.
So im creating an app that has 5 fragments. the first one has a spinner, the next 3 have each of them 1 edittext, and the last one has a textview. My problem is, i want to collect the user input from the edittext's and the spinner and use it on a formula that is going to give a result to be shown on the last fragment.
And what i need to know is how do i get the user input from the edittexts and the spinner so i can use them on the formula.
For you guys to have an idea of what im aiming for here is a video that i found: http://www.youtube.com/watch?v=gcap7DUgIHg
(I have done other apps that use a basic layout with the edittexts all on one activity, but i wanted to try with the type of layout you see on the video)
I want my app to work exactly like that one, but instead of using numberpickers i use edittexts and a spinner.
This is probably a lot for anyone to explain, but i have been on this forever and i need to deliver this school project tomorrow. Hopefully anyone can give me a help with this as fast as possible.
I appreciate any help given!
Thank you
Here is the code:
MainActivity- http://snipt.org/BGaf2
ResultFragment- http://snipt.org/BGag2
One of the Fragments(Basically all the same)- http://snipt.org/BGah5
PS: SORRY FOR ALL THE COMMENTED CODE AND THE LONG POST, I COULDNT PUT MORE THEN 2 LINKS BECAUSE OF MY REPUTATION
EDIT: Thanks for the reputation! I can now post more than 2 links

Gather parts from layout, java android

Im pretty new at programming android and this is my problem:
I have a layout page that i have alot of information on, including buttons and textedits. Now i want to split it up in different parts, without having to create different layouts for every headline. So for example, if i choose to see "Information 3" i want to hide everything else on the layout except the "information 3 text/buttons/textedits".
Is it possible to do this? Because i really dont have time for making a new layout for every headline, and i dont want to show every headline at the same time. (I want to keep all information/data in the same layout file)
Maybe there is a smarter way to do it? Thanks in advance!
/Erik
You can call view.setVisibility(View.GONE) if you want to remove it from the layout. you can search some more questions like these:
hide/show on click of Button
how-to-show-hide-grouped-views
Try these and if u need more help then let me know

Updating the number of radiobuttons and their labels in android quiz

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

How to Create a Java Quiz GUI?

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.

Categories

Resources