I want to make a quiz application for android,where each page will have a single question and on click of next button second question will be displayed,
I want to keep the next button common and use single fragment to display different layouts on click of next button.And on the basis of answer submitted next question will be displayed.
How to achieve this.How to use single fragment for multiple layout and maintain its stack.
Using different layouts to load various questions would be an incorrect solution to your problem, rather fetch the data from your question bank(xml, excel, db, any source) and set your question TextView to it. The Multiple choice answers(if any) could also be populated in the same way on a single fragment. You would just need one single layout.
Related
I am trying to create a fragment and inside that i want to create multiple textviews whoose text is set from the data retreived from the database(mysql).
And also i want to have the feature "refresh" by which the textviews are updated with recent data from the database.Iam trying to do that but iam not getting enough idea how to do it as iam new to android programming.
Please help me with this. thank you in advance and any suggestions are acceptable.
i.e
I have database of a person and i want to get his name and address from that,then in my activity i want to create a fragment that displays a name and address in separate textboxes and if address or name exceeds some length then i can press "more" to see left information
Consider using a ListView to populate data from the database, and a SwiperRefreshLayout to refresh it. Check these links for more info :
SwipeRefreshLayout
ListViews
The answer depends on what your app will do.
If you have a fixed number of TextViews, and the number won't change in the future or depending on the answer to the database query, you could simply stick to normal TextViews; if the number changes, I suggest using ListViews or ExpandableListViews.
Regarding the layout, you can create a normal layout using AndroidStudio's layout designer, and then inflate it to your view.
For the refresh, you can add a button that calls the method in which you fill the textviews/listviews.
Actually your question is too broad: if you want a more specific answer, you should edit it asking what you really need.
my problem goes like this-
this is a commercial application in which users can purchase different products they see within app..
there is one view cart button available on the main screen
there are 10 different products available in an activity and there are 3 such activities( each of them containing various different products)
these products are arranged in a linear fashion (linear layout).
every product is having an add to cart image button.
what i want is, when the user presses that button, 3 things should happen..
a new activity will be created containing that product information (when the user presses another "add to cart" button, this new product will come below the previous product and so on).
there is one cart button in the menu bar, that cart should show a number equal to the nos of product in the cart.
its simple, a small flash notification that the product has been added to the cart.
any help will be deeply appreciated.
You would see some benefit by using Fragments instead. Use a main Activity as a "switchboard" and multiple Fragment instances to show the per item details.
You don't need to dynamically create a new Activity. Taking into consideration that you call yourself a newbie in android development, I can only tell you what to study to accomplish your plan.
First, learn to make an Activity that will contain a ListView. Make an XML layout for your ListView items, containing TextViews, Buttons, whatever you want. Then, make an adapter that will fill items with corresponding values (texts, button names, images, etc).
And second, make them all clickable (onItemClickListener or an onClickListener for every button) and make your Activity get inflated with a Fragment containing TextViews, ImageViews, etc... whatever you need to represent information about the item selected.
The best practical way is to make an empty Activity with an empty Fragment. The last one will be either inflated (populated) or even replaced with whatever things you need.
Sorry, but teaching you how to make all these things technically is beyond the scope of any sensible answer that someone can post here. It's all the matter of study and practice. But I hope the vector of study I gave you is transparent and affordable.
For a school project a need to build a android quiz application with multiple question types. These question types are: Multiple Choice, Textbox, Radio button and a minigame in which you need to sort images in the right order in a draggable gridview.
I think to use multiple activities for this isn't needed and that i just can switch the overall layout between multiple xml layout files for each of these question types if i first check what the type of the question is. Most other posts on stackoverflow are only related to quizzes with one type of question, without minigames in between the questions so i wanted to know what the best method is to switch between these different question types and layouts. At least i know i need a switch/case to check the different question types (for my prototype located in a array) and switch to right type if you press the "Next question" Button that is located under the answers (under the gridview in case of the minigame).
I already searched on the internet for it and i found the following options but i don't know what's best in my case. I also wanted to make the app compatible with android version 2.3.3. Some examples could also help me very much!!
(Adapter)Viewflipper
An Adapter that changes a inner layout
setContentView() of the main activity
Including a layout in another layout and change it
Make some views/layouts visible and invisible.
Make a new activity for each question (if there is no other option)
You can do it with a ViewFlipper. In the ViewFlipper XML, just list each layout for each question type and just have the user scroll through the flipper to get to the type they want. You can probably do this by setting a OnTouchListener and calling showNext() as they scroll.
Setting the correct data for each view is solely up to you; you would just have to match the correct data based on what view they are in to populate it correctly. That's it :)
It depends on how you want to structure your quizes are the questions supposed to be mixed together? Are they all seperate quizes.
If they are separate the easiest approach would probably to implement a view pager. With the view pager it will create a new fragment for each page. From here you have a two options, you can either create a new fragment for each quiz type. Or you can create one quiz fragment and pass an argument to that fragment to select the correct layout. Either way you'll likely want a new layout for each quiz type. As for your minigame you can just include that as a page in your view pager in between two quiz views.
All of the above will work on 2.3 and above if you use the support library. I would recommend checking out some tutorials on viewPager they are fairly straightforward to use.
I wanted to develop a survey app, which contains a single view and the contents of the view should change dynamically based on the questions type.It has two buttons "back" and "next", when i click "next" it should move to next question and clicking "prev" button it should take us to previous question.How to achieve it in android ?
Use fragments. http://developer.android.com/guide/components/fragments.html
Create multiple layouts inside single xml and then u can display only one page in layout rest hide .and. Use. Different IDs for all the page so that u can hide properly
Background:
I'm creating an Android app (my second) and I'm not really sure how to structure it.
The section of the app I'm having issues with is basically a sort of simple catalogue; a user clicks a button which opens a layout containing a title (TextView) and an image (ImageView).
Image for clarity:
What is the best way to structure this? Since I'm pretty new to Android development, my approach would have been to create an activity for the first view (no.1), create a seperate activity for each of the "Products"-pages, "Products 1", "Products 2" etc. and a third activity for the single item view.
I know how to reuse the "single item"-layout (no.3) but I'm not really sure what the best approach is for no.2.
Question:
Should I create six new activities for "Products 1", "Products 2",..,"Products 6" and corresponding layouts for each? Or should I try to keep the number of activities to a minimum?
Any help is highly appriciated.
Thanks!
Your app is like a tree-structure app, so three activities/views are enough for your application.
Products Category List(Contains Product1, Product2, etc.)
Product List(Contains Product1-1, Product1-2, etc.)
Product(Contains image for a product)
You should not create an extra activity for every product because it will consume too many system resources.
For coding, you can make a base class since these three activities are similar, and put common elements into the base class.
If you use listviews the first two screens can be just one activity, with different data passed in to display screen 2. And screen 3 will be common for all, another activity.
If you are planning on keeping the screens as you displayed above, with buttons, then you can just create one layout with button, use it as a row layout within a listview. The activity logic would be such that, depending on data, it would populate one or more rows. With this option too you can do screens 1 and 2 using one activity and one set of layouts.
You make one layout:-
1. layout one you can visible(visibility) first 6 textview and other will b gone(visibility).
2. Layout two you can visible(visibility) textview what you want and other will b gone(visibility).
3. Layout three you can visible(visibility) only image view and other will b gone(visibility).
note:- change textview value through setText.