Assuming some logic that deals with measure units and the user is asked to choose between US and metric systems, what would be the better UI choice: using 2 CheckBoxes or RadioButtons? Is there an easy way to ensure just one View is checked?
Checkboxes are useful when you want the user to select multiple options.
Radio buttons are useful to guarantee a single option among multiple options. However, if you have a fair amount of radio buttons the user interface becomes a mess. Therefore, for those cases, Spinners are the best answer for your problem.
If you use Radio Buttons you can guarantee they only use one radio button using RadioGroups.
I would use a Spinner if I were you. It'll allow you to add other unit systems in the future.
Through radio button group you can do it. Just use a RadiobuttonGroup widget mention your radiobutton properties.
Simple. If you can't follow some of procedures I suggest going and look for tuts on them
First: Go to your xml file
Second: Create Radio group
Third: Create Radio button in between
Forth: make sure you have the id of the radio button.
fifth: call the item on your main class. RadioButton name = (RadioButton)findViewById(R.id.radioButton Name);
Now you can program the rest everything really just follows this order for anything in .xml. You need it call it and create and ID simple. Next time just look at youtube vids. I recommend the website TheNewBoston.org best tuts you'll ever encounter in a life time for almost all programming languages.
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.
This is more of an opinion based question.
I'm working on an app that will give the user a choice of 2 items of which the user must choose one. Now to implement this, we have :-
RadioButtons in a RadioGroup
Spinner
For such a basic thing, I think I can should go with RadioButton but they don't look much aesthetically pleasing as much a Spinner looks but a Spinner is basically used for more than 2 items generally.
So I'm all confused as what would be better UI/UX wise.
Can someone please help me out on this one?
For two options, why not use a Toggle Button?
http://developer.android.com/guide/topics/ui/controls/togglebutton.html
In my application I currently have an xml layout that is re-used to enter information 6 times (these are turns in a game). This works fine. At the end of the round I present a screen that has a summary of each turn. I want to implement a button beside each turn to "edit" that turn. There are 3 possible things that can be edited. Ideally an alert dialog or something like a "popup" would be idea for this.
Would I be best off to have 3 buttons per "turn" for editing or is there a way to do this with a popup?
Thanks for your input on this matter.
You could list each turn and it's information with a single edit button next to each. When the edit button is pressed, create a new activity (intent) that prompts for all three pieces of data.
You have several options (and probably more I'm not thinking about). If these are in a ListView (or even if not) you could use a ContextMenu. You could have options in here to change the selected item or others. This would show a popup when the user long clicks the item
A PopupMenu can give you a similar effect that can pop up a list of options when the user clicks on a Button. Note that this requires API >= 11
You also could use an AlertDialog, as you mentioned. But just from what little I know about what you are trying to do I'm not sure this is what you would want.
Again, I don't know enough details about what you have or want but I would say that one of the first two options would suit you best. As far as one Button or multiple Buttons, that depends on the layout that will work best for your app, I suppose. You certainly could have one "Edit" Button which uses something like a PopupMenu and allows the user to choose what to edit. I hope this helped a little.
I apologize for yet, another beginner question. I have a .Net background and this is my first time with Android.
In .Net I could use panels to show/hide controls, and I'm looking to do the samething in Android.
This is what I'm trying to do: There will be two radio buttons on the top: Basic and Advanced. Depending on the radio button clicked, I want to show the relevant form. How can I possibly accomplish this?
Thanks!
you can use setvisibility for the view
you have to register for CheckedChangeListener using setOnCheckedChangeListener for the radiogroup
In the onCheckedChanged
you have to do
hidingView.setVisibiliity(View.GONE)
showingview.setVisibility(View.VISIBLE)
You could just put each one of your forms into its own FrameLayout and then use a conditional statement that checks for the state of the radio buttons. I dont know what kind of format your forms are in but Im imagining theyre probably a series of edittext boxes and TextViews. It would probably be easiest if you set it up your xml layout, declare the view to place one form and then add the other forms content to the FrameLayout dynamically in java according to the radio buttons pressed.
I was told that I have to use a hash-map to store radio buttons. (The buttons as the key and their state as value) but I am new to Java and Android so It's kinda confusing.
I have a choice test with multiple questions and yes or no answers and I want to count the yes answers.
Maybe it's some simple thing to do but I can't figure out.
Any help would be appreciated.
Thanks
You could add a reference to all of your objects to a collection and iterate over them checking whether they are checked and counting them up.
Alternatively you could register an onClick listener on all of the buttons and increment/decrement a count when they are clicked.
There are multiple ways you could achieve this. I dont see why you need a hash map though, as the checked state is available on the button object itself. Your hash is useless.