public class

ComboBox

extends View
java.lang.Object
   ↳ com.neomades.ui.View
     ↳ com.neomades.ui.ComboBox

Class Overview

A ComboBox represents a list of choices into screen in order to intercept events (touch and keys) to set a selected value from a list of choices.

Handling Selection

 ItemSelectedListener comboBoxListener = new ItemSelectedListener() {
 	public void onItemSelected(int index, String item) {
 		// do some stuff
 	}
 }
 ComboBox myComboBox = new ComboBox();
 // add items here with ComboBox.addItem() methods
 myComboBox.setItemSelectedListener(comboBoxListener);
 

Default properties

By default, the following properties are applied to a new ComboBox:

  • focusable (limited to some devices)
  • clickable
  • enabled
  • text : select item or empty
  • no icon
  • width content stretch : MATCH_PARENT.
  • height content stretch : MATCH_CONTENT.
  • content alignment : HCENTER|VCENTER.

Summary

XML Attributes
Attribute Name Related Method Description
font setFont(Font) Font resource id: Res.font.FONT_XXXX  
textColor setTextColor(Color) #AARRGGBB or a color  
textSize setTextSize(int) a size in dp  
[Expand]
Inherited XML Attributes
From class com.neomades.ui.View
[Expand]
Inherited Constants
From interface com.neomades.ui.Alignment
From interface com.neomades.ui.StretchMode
Public Constructors
ComboBox()
Constructs a combo box with no elements
Public Methods
void addItem(String item)
Adds an item to the ComboBox
void addItem(int resId)
Adds an item to the ComboBox.
String getItem(int index)
Gets the item at the given position.
int getSelectedIndex()
Returns the selected index
String getSelectedItem()
Returns the selected item.
void insertItem(int resId, int index)
Inserts an item at the given position
void insertItem(String item, int index)
Inserts an item at the given position
static void openChooser(View origin, String[] items, String selectedItem, ItemSelectedListener listener)
Opens a dialog chooser used to select one item from a range of many items.
void removeAllItems()
Clears all the items of the combo box
void removeItem(int index)
Removes an item from the combo box
void setFont(Font font)
Set the font of the selected item.
void setItemSelectedListener(ItemSelectedListener listener)
Sets the listener on this combo box, to listen when the selection changes
void setSelectedIndex(int index)
Sets the selected index of the combo box to the index given in parameter
void setSelectedItem(String item)
Sets the selected index of the combo box to the index given in parameter.
void setTextColor(Color textColor)
Sets the button text color.
void setTextSize(int sizeInDp)
Sets the text size to a given value (in dp).
[Expand]
Inherited Methods
From class com.neomades.ui.View
From class java.lang.Object

XML Attributes

font

Font resource id: Res.font.FONT_XXXX

Related Methods

textColor

#AARRGGBB or a color

Related Methods

textSize

a size in dp

Related Methods

Public Constructors

public ComboBox ()

Constructs a combo box with no elements

Public Methods

public void addItem (String item)

Adds an item to the ComboBox

Parameters
item the string to add to the combo box
Throws
CrossThreadException if the method is called from outside the UI-Thread

public void addItem (int resId)

Adds an item to the ComboBox.

Parameters
resId the string id assigned added to this combo box
Throws
CrossThreadException if the method is called from outside the UI-Thread

public String getItem (int index)

Gets the item at the given position. If none is found, return null

Parameters
index the index of the item to find
Returns
  • the item, or null if not found

public int getSelectedIndex ()

Returns the selected index

Returns
  • the selected index (0 based)

public String getSelectedItem ()

Returns the selected item.

Returns
  • the selected item

public void insertItem (int resId, int index)

Inserts an item at the given position

Parameters
resId the string id assigned added to this combo box
index the index where to insert
Throws
CrossThreadException if the method is called from outside the UI-Thread

public void insertItem (String item, int index)

Inserts an item at the given position

Parameters
item the string to insert
index the index where to insert
Throws
CrossThreadException if the method is called from outside the UI-Thread

public static void openChooser (View origin, String[] items, String selectedItem, ItemSelectedListener listener)

Opens a dialog chooser used to select one item from a range of many items.

Parameters
origin the view from where to show the dialog (usefull for iOS)
items list of items
selectedItem the original selected item
listener callback to listen the new selection (could be null)
Throws
NullPointerException if origin is null in iOS platforms
IllegalArgumentException if items is null or empty, if selectedItem is null.

public void removeAllItems ()

Clears all the items of the combo box

Throws
CrossThreadException if the method is called from outside the UI-Thread

public void removeItem (int index)

Removes an item from the combo box

Parameters
index the index where to remove the item
Throws
CrossThreadException if the method is called from outside the UI-Thread

public void setFont (Font font)

Set the font of the selected item. This method does not change the font of the items in the opened chooser.

Related XML Attributes
Parameters
font the new font to set
Throws
CrossThreadException if the method is called from outside the UI-Thread
NullPointerException if the font parameter is null

public void setItemSelectedListener (ItemSelectedListener listener)

Sets the listener on this combo box, to listen when the selection changes

Parameters
listener the listener

public void setSelectedIndex (int index)

Sets the selected index of the combo box to the index given in parameter

Parameters
index the index to select
Throws
CrossThreadException if the method is called from outside the UI-Thread

public void setSelectedItem (String item)

Sets the selected index of the combo box to the index given in parameter. The item selected will be the first in the combo box that is equal to the String given in parameter.

Parameters
item the item to select
Throws
CrossThreadException if the method is called from outside the UI-Thread

public void setTextColor (Color textColor)

Sets the button text color.

Related XML Attributes
Parameters
textColor new color for the text
Throws
CrossThreadException if the method is called from outside the UI-Thread
NullPointerException if the parameter is null

public void setTextSize (int sizeInDp)

Sets the text size to a given value (in dp).

Related XML Attributes
Parameters
sizeInDp size to set to the text