0

I want to display button and drop down on a same screen and want to capture it using fieldChnageListener ,i am not able to get how to add these both on the same screen.I have the following code :

ButtonField btnSubmit = new ButtonField("Submit!",
ButtonField.CONSUME_CLICK);
         FieldListener listener = new FieldListener();
               //assign that listener to the button
               btnSubmit.setChangeListener(listener);
               add(btnSubmit);

 class FieldListener implements FieldChangeListener {
       public void fieldChanged(Field f, int context){
           //if the submit button is clicked
           if (f == btnSubmit){
                getCalender();
               //if the EditField is empty
               if(editField.getText().equals("")){
                   Dialog.alert("Please enter timezone in the field.");
               }else{ // if it is not empty, display the message
                   Dialog.alert("TimeZone is"+editField.getText()+"!");
                    timeZone = editField.getText();


               }
           }
           if(f == editField) {
               //text changed in the ef-Field (EditField)
           }
       }
   }

how to add a drop down here?

sheetal_r oswal
  • 155
  • 2
  • 2
  • 10

1 Answers1

1

here how can you do this ..

If your class is implementing FieldChangeListner then in its fieldChanged method do like this

public class Demo extends mainScreen implements FieldChangeListener {
public Demo () {
ButtonField btnSubmit = new ButtonField("Submit!",
ButtonField.CONSUME_CLICK);
           //assign that listener to the button
           btnSubmit.setChangeListener(this);
           add(btnSubmit);
}

   public void fieldChanged(Field f, int context) {
       //if the submit button is clicked
       if (f == btnSubmit){
            getCalender();
           //if the EditField is empty
           if(editField.getText().equals("")){
               Dialog.alert("Please enter timezone in the field.");
           }else{ // if it is not empty, display the message
               Dialog.alert("TimeZone is"+editField.getText()+"!");
                timeZone = editField.getText();


           }
       }
       if(f == editField) {
           //text changed in the ef-Field (EditField)
       }
   }
}

this should work.

BBdev
  • 4,898
  • 2
  • 31
  • 45