Android layouts: how to approach dynamic generated survey forms - android

I need to develop a survey application.
The user will make some choices first and then the appropriate list of questions will be shown.
Since I have a list of more then 2000 questions to choose from, it is impossible to create a XML layout for each type of survey. The idea is to iterate through a local SQLite database where the questions are stored and show only those which meet the parameters set at the beginning by the user.
Is creating the layout at runtime in Java the only solution? I would like to keep the application views separated from the application logic. The questions will be of multiple types (multi-choice, radio buttons, drop-downs...)
Any suggestions?

You can create a template for each of the question types in xml and then just inflate that at runtime and fill in the correct information. This will allow you to redesign the look without having to touch code.

Related

Suggestions for data entry form in android

I am working on app which have data entry form which have
Some fields with 3 drop down associated to it.
More then 25 input fields (input box, radio button, drop downs etc)
All input fields are grouped into 3 categories
My question are:
How to display field with 3 drop downs associated with it ? Because of a small screen size it cannot be displayed horizontally.
What is the best way to represent 25+ fields ? I tried scroll view and tabs but don't find it so pleasing.
For example if you consider date then it may have three drop downs for date , month and year. (Its just example I have fields different than date)
What is the good way to have fields in a category together with appealing UI.
PS: My app is related to Hospital so it has to be pleasant .Which also means I cannot use glossy background or image.
You might want to check this site for general Android UI design ideas. Here are some for your particular cases:
re-design your UI to only show what is needed. It's unlikely that all 25 fields are used all of the time. Consider separate screens for different use cases, and/or some sort of wizard-like UI (fill in the basics, press next, fill in details, etc.)
if you really need to display all of this, consider using a tablet, not a phone to run the app (assuming this is to be used in the field, and you have some control over devices).
instead of tabs, you might want to try something like ViewPager. It doesn't take as much space as tabs, and the number of views is practically unlimited.
Maybe like this...
You can use the library QuickAction which allows to create some kind of context menu.
To keep a simple screen view, you can only display the current values. Several on the same lines for the same category.
Then, if the user click on a value or category, you trigger a QuickAction with the actions available for the category or values: Edit, clear, ...
For each action, you can also show a dialog to update/fill the field which has triggered the action...

Dynamically generate android XML

I´ve been working on a project, where the user should be able to choose an option from a spinner and depending on the selection, a specific form should be generated.
Now, I just have one standard android-xml for all the selections, and an onItemSelectedListener for the spinner.
I´m not sure how to get this going. Should I generate all the layout in plain java, or should I make a xml-layout to include in some way?
If I understand it well you want to create a short of configurable form.
To do so you can create a XML layout with all the available options of the form. Then by code, depending on the user selection add or quit elements with the View setVisibility() method and show the layout.
In case you have many forms or they are too big or complex, you can have as many XML layouts as different forms you have and then show one or another based on the user selection.

Creating a dynamic app in Android

I am currently looking to create an application in Android where a user can answer a questionnaire and that information is saved. The questionnaire will be in a sqlite database and can have different set on answers, and their can be several questionnaires the user can choose to fill. how do i go about firstly having the ability to create a dynamic questionnaire view for the user?
You can add your questions in code?
Get your all questions from the database, and pick your questions, or just query them with a limit and an order by rand()
Then instead of hardcoding the questions in xml, you'll add them to your views with .setText()
You can fetch questions from random rowids and present them... So, each time u execute, you will be fetching random questions from SQLite database and hence different questionnaire...
I think you can take to approaches:
1 - create a web-based view. You must read the questionnaire and generate the html, then present it in a WebView.
2 - generate a xml layout and inflate it. With "inflate" i'm referring to use the object LayoutInflater with some of inflate calls that accept an XmlPullParser, it's must generate a view exactly identical to a view defined in the IDE. I never test it so please let my know if it's works.

How to deal with dynamic lists of data in a layout

I want to display contact information in a custom layout. My app lets the user select a contact, then I retrieve key pieces of info on that contact (phone #'s, email addy's, etc). I want to display them to the user so they look grouped logically. Sort of like a series of tables, so phone numbers, then email addys, then organization, etc.
I have a table format that I've been using in a different part of the app where I know the exact number of rows I'm adding and I have defined styles for the rows already. I want to reuse those styles for this data, but android sdk won't allow for you to set the style attribute programmatically.
I could create the tables in code and set all the attributes the same as in my defined styles, but it seems like a lot of extra coding. Any ideas on how I should approach this problem?
Sounds like you need a TableLayout.
To reuse styles externalize them to resource end then you can apply them in multiple places.

How to achieve tags related functionality in android?

friends,
i want to perform functionality same like stackoverflow tags as we do normally creating a question separated by commas in android.
i know we have auto complete text view in android any one suggest me can i use it for multi selection?
or any useful way to achieve this?
any help would be appreciated.
it can be achieve through two ways
i devised my own machanism so may b you people have better approach than me please share too.
1) simple
2) advance
1) in simple we can use autocomplete text view and only use single tag with hard coded values which is limitation.
2) i have used a popup page with a Edittext and add button on top and listview with checkboxes below it.
fixed items i have already loaded into list view with checkboxes so that i could select multiple tags.
and in case of if i want to add my custom tag then i use that edit text above list view and store it in temporary data and
then finally using bundle i show selected values where i want seperated by commas.
thats it.

Categories

Resources