i have a spinner with an arrayadapter that is dynamically managed. when it gets displayed, the spinner text also displays the radio button. how do i get rid of this radio button? the drop down arrow is all strecthed and yucky... thats my problem. NOTE: i'm not talking about the radio buttons that appear in the list that is displayed when i select the drop down on the spinner.
here are the appropriate code snippet... couple of points:
Q: what am i missing? seems to me i'm missing some attribute of the Spinner which is causing the radio button to also display in the text part of the spinner.
-- snip code --
public class ChoiceGroupImpl extends Spinner implements OnItemSelectedListener {
public ChoiceGroupImpl(Activity activity, WidgetContainer container, Value widget, AttributeImpl attributes, Object[] value, int selected) {
...
adapter = new ArrayAdapter<CharSequence>(activity, R.layout.simple_spinner_dropdown_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
for (int i = 0; i < value.length; i++)
adapter.add(value[i].toString());
if (attributes.isReadonly())
setEnabled(false);
setAdapter(adapter);
setSelection(selected);
setPrompt(adapter.getItem(selected));
setOnItemSelectedListener(this);
...
}
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
setPrompt(adapter.getItem(position));
((ToolkitImpl) Toolkit.getInstance()).hiddenCommand(container, "SelectionChanged");
}
...
-- end snip code --
To set a radio button to checked/unchecked, select the element and set its checked property to true or false , e.g. myRadio. checked = true . When set to true , the radio button becomes checked and all other radio buttons with the same name attribute become unchecked.
In Android, RadioButton are mainly used together in a RadioGroup. In RadioGroup checking the one radio button out of several radio button added in it will automatically unchecked all the others. It means at one time we can checked only one radio button from a group of radio buttons which belong to same radio group.
If you want to keep radio button in the spinner, but not in the textview then do this:
adapter = new ArrayAdapter<CharSequence>(activity, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
use simple_spinner_item instead of simple_spinner_dropdown_item while creating your adapter
adapter = new ArrayAdapter<CharSequence>(activity, R.layout.simple_spinner_item);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With