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.
Related
I want to create 16 buttons each have different texts on it.Those text will be picked up randomly from an array depending on another random value.Lets say,
I have 3 words (apple,banana,watermelon), when the activity created it will pick up one of these words.Lets say apple.And in this activity's screen there will be 16 buttons.These buttons must have the letters that apple consists of "a","p","p","l","e" and the remaining buttons will be filled up with other remaining letters of the alphabet.
So in my case what I wonder is should i do the button creation programmatically by taking a value and assigning this value on creation one by one or do it in the xml and leave their text parts and fill up programmatically.
These 2 options in detail :
First : I'm going to create a function which takes a String value as a paramater and returns a button with this text set on it by using setText(); and then locate it in the layout.
Second : I create the layout with those button and leave blank their text parts and in the activity I only assign their letter values.
I vote for the second option but I'd like to know what's your opinion and would there be a difference in terms of performance or memory ?
The disadvantage of declarative approach is that you can get only so
far with XML.
XML is great for look and feel of your user interface, but it does not provide a great way of handling user input. That's where the programmatic approach came.
Everything you can do declarative as well as with programmatically. But java also allows you to specify what happens when the button is actually clicked.
This is the main advantage of programmatic approach to the user interface.
So what is Best ?
Here it is , Both are good at thier point.
1) Use XML , when everything about your user interface is static , such as layout of the screen , all the widget etc.
2) Then switch to the programmatic approach when user interacts with various widget in the user interface.
In other words you would use XML for what the button Looks like and
Java to specify what it does.
I am just starting with android. This is what i want to make:
Now when you click on From, a new screen would open where you can select places and once you select you will get back to this screen where instead of "Bangalore" it would be the place you selected.
What kind of a field is this ? Text field ?
Also if i want to add any effect like when you click on it its color changes, how would i go about it ? Any tutorials or documentation i can check out for this.
Yes, you will probably want to use TextView.
You can change the text it displays by using SetText(), and you can change the text color by using SetTextColor().
You need a TextView to display text, but if you want to display an image, text and be able to interact with that, then Button or ImageButton is what you need.
Your question is too broad, so I encourage you to start doing some tutorials. To implement all that stuff you'll need to learn about layouts and activities, dialogs, listviews, ... Basic Android, but it needs a minimum of experience.
Is there any shortcut for editing properties of a widget in Android Layout editor in ADT?
I need to change gravity of TextView lots of times, but every time I have to use mouse...
You could do a search and replace on a particular string in the layout.
Highlight only the TextViews you want the search to happen in
Search > Search
Enter the string to be replaced and press the "Replace" button or "Replace
All" button.
If you post the exact xml listing of your layout, I can be more exact in which string needs to be replaced. If that solution doesn't work for your particular case, to save some time, I suppose you might also be able to create a particular custom Eclipse template for your TextView.
A third option would be to use inheritance and create a customTextView with the gravity already set a certain way.
And a fourth option still would be to set the properties of your TextViews programmatically after the fact using both XML and Java (instead of only using XML).
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.
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.