0

I want to create a function which takes two arguments

  1. A String value (name)
  2. An array of String objects

The function creates LWUIT Combobox with these two parameters and returns a ComboBox varialble...

I have written following code ...

 public void createComboxBox(String recStoreName,String [] values){
    comboBox = new ComboBox(recStoreName, values);
    surveyForm.addComponent(comboBox);

}
Lucifer
  • 29,392
  • 25
  • 90
  • 143
Amit
  • 13,134
  • 17
  • 77
  • 148
  • 2
    1. That's a method, not a function. 2. You must "return comboBox;" at the end of the method. 3. Must declare return type as ComboBox instead of void. – ignis Jul 04 '11 at 11:00

2 Answers2

2
   //create a form and set its title
    Form f = new Form("Simple ComboBox");

    //set layout manager for the form
    //f.setLayout(new FlowLayout());

    //set form background colour
    f.getStyle().setBgColor(0xd5fff9);
    .
    .
    .

The first two lines of code are quite self-explanatory and should be familiar to AWT/Swing developers. The third line sets the background color attribute for the form.

The combo box is also instantiated in a similar manner:

    // Create a set of items
    String[] items = { "Red", "Blue", "Green", "Yellow" };

    //create a combobox with String[] items
    ComboBox combobox = new ComboBox(items);

Resource


Also See

jmj
  • 237,923
  • 42
  • 401
  • 438
  • thanks Jigar.... I have done something similar ... problem is I dont know how to add the recStoreInformation (the first parameter) with the ComboBox..... – Amit Jul 04 '11 at 11:37
  • `recStoreInformation ` did you mean instance of `RecordStore` ? – jmj Jul 04 '11 at 11:40
  • He need like passing the key and value in the combobox. – bharath Jul 04 '11 at 11:44
  • 1
    @Amit if @Bhakki sais is true then [I don't see any relevant constructor for combobox](http://lwuit.java.net/nonav/javadocs/com/sun/lwuit/ComboBox.html) What you can do is, pass labels to Combobox. and maintain its value in a `Vector` and have a mapping based on the index – jmj Jul 04 '11 at 11:49
1

Just create the bean class like set the key and value. For example,

public void beanClass {

String value;
String key;

 public beanClass() {
} 
public void setValue(String value) {
this.value = value;
public void getValue() {
return value;
}
public void setValue(String key) {
this.key= key;
public void getKey() {
return key;
}
}

then create the beanClass array on your class and pass the Key's and Value's. then pass the beanClass array to ComboBox.

comboBox.getSelectedItem() returns the beanClass. So you can get the key and value from selected beanClass.

bharath
  • 14,283
  • 16
  • 57
  • 95