2012-03-19 7 views
3

画像のオンスクリーン私はドロップダウンメニューからデータを選択した後、データを選択してポップアップした場所に画面に渡す必要があるドロップダウンコードを持つスクリーンをポップアップしています。選択したocf値を最初の画面に渡して消えるはずです。私は、これは、ポップアップ画面ポップアップスクリーンでの問題

ある このコードは、ポップアップ画面を呼び出します

戻って最初の画面に
if (field==bitmapField1) { 
    UiApplication.getUiApplication().pushScreen(new MyPopup()); 
} 

選択後popupscreenを非表示にすることはできませんよとデータを渡すことができないのです

public class MyPopup extends PopupScreen { 
     ObjectChoiceField ocf; 

     public MyPopup() { 
      super(new VerticalFieldManager(), Field.FOCUSABLE); 
      // this listener 'listens' for any event (see at the bottom) 
      FieldListener listener = new FieldListener(); 

     TimeZone[] zone = TimeZoneUtilities.getAvailableTimeZones(); 
      ocf = new ObjectChoiceField("Set Timezone", zone); 
      ocf.setChangeListener(listener); 
      add(ocf); 
     } 

    class FieldListener implements FieldChangeListener { 
      public void fieldChanged(Field f, int context) { 
        if (f == ocf) { 
         Object ob = ocf.getChoice(ocf.getSelectedIndex()); 
         String str = ob.toString(); 
         Dialog.alert(str); 
        } 
      } 
    } 
} 

答えて

1

PopUpを起動した画面を参照する属性をPopUpScreenに追加する必要があります。 synchronized EventLock

if(field==bitmapField1){ 
    UiApplication.getUiApplication().pushScreen(new MyPopup(this)); 
} 
0

開くダイアログ:あなたがポップアップを起動したときに

public class MyPopup extends PopupScreen { 
    ObjectChoiceField ocf; 
    MainScreen parentScreen; 

    public MyPopup(MainScreen parentScreen) { 
      this.parentScreen = parentScreen; 
      ... 

をそして:その方法は、あなたは問題なく、親画面にパラメータを送信することができます。 あなたの解決策を得るでしょう...

synchronized (UiApplication.getUiApplication().getEventLock()) { 
    //Open your dialog here......  
    UiApplication.getUiApplication().pushScreen(new MyPopup()); 
} 
1

ここは私のCustomChoiceFieldです。それがお役に立てば幸い:あなたのポップアップ画面のObjectChoiceFieldで

public class ChoiceField extends HorizontalFieldManager{ 
    protected boolean isEnabled = true; 
    protected String label; 
    protected Object[] choices; 
    protected int selectedIndex = -1; 
    protected ButtonField chooseField; 
    protected Font textFont = ClientConstants.Fonts.NORMAL; 
    protected PopUpList popup; 
    private FieldChangeListener fieldChangeListener; 

    public ChoiceField(final String label,Object[] choices){ 
     this.label = label; 
     if (choices == null || choices.length == 0){ 
      this.choices = new String []{}; 
      setEnabled(false); 
     }else { 
      this.choices = choices; 
     } 
     chooseField = new ButtonField("Please Choose"); 
     chooseField.setChangeListener(new FieldChangeListener() { 
      public void fieldChanged(Field field, int context) { 
       UiApplication.getUiApplication().invokeAndWait(new Runnable() { 
        public void run() { 
         if (isEnabled){ 
          UiApplication.getUiApplication().pushScreen(popup); 
         } 
        } 
       }); 
      } 
     }); 
     chooseField.setPadding(0, 0, 0, Display.getWidth() - 20 - chooseField.getPreferredWidth()); 
     popup = new PopUpList(this.choices); 
     add (chooseField); 
    } 
    public void setChoices(Object[] choices) { 
     if (choices == null || choices.length == 0){ 
      this.choices = new String []{}; 
      chooseField.setLabel(""); 
     }else { 
      this.choices = choices; 
      chooseField.setLabel(this.choices[0].toString()); 
     } 
     popup = new PopUpList(this.choices); 
    } 
    public void setChangeListener(FieldChangeListener fieldChangeListener){ 
     this.fieldChangeListener = fieldChangeListener; 
    } 
    public void setEnabled (boolean isEnabled){ 
     this.isEnabled = isEnabled; 
    } 
    public Object getSelectedItem() throws ChoiceFieldNotSelectedException{ 
     if (selectedIndex == -1){ 
      throw new ChoiceFieldNotSelectedException(label); 
     } 
     return choices[selectedIndex]; 
    } 
    public void setSelectedObject(Object selectedObject){ 
     for(int i=0;i<choices.length;i++) 
      if(choices[i].equals(selectedObject)){ 
       selectedIndex = i; 
       break; 
      } 
     chooseField.setLabel(choices[selectedIndex].toString()); 
     ChoiceField.this.invalidate(); 
    } 
    protected void paint(Graphics graphics) { 
     if (label.length()>0){ 
      graphics.setColor(Color.WHITE); 
      Font f = textFont; 
      while (f.getAdvance(label + ": ") > Display.getWidth() - 30 - chooseField.getPreferredWidth()){ 
       if (f.getHeight() == 8){ 
        break; 
       } 
       f = f.derive(f.getStyle(),f.getHeight()-1); 
      } 
      graphics.setFont(f); 
      graphics.drawText(label + ": ", 10, (chooseField.getHeight() - textFont.getHeight())/2); 
     } 
     super.paint(graphics); 
    } 
    class PopUpList extends PopupScreen{ 
     private ObjectListField listField = null; 
     public PopUpList(final Object [] choices) { 
      super(new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR)); 
      listField = new ObjectListField(choices.length){ 
       protected void layout(int width, int height) { 
        super.layout(Math.min(width, getPreferredWidth()), height); 
       } 
       public int getPreferredWidth(ListField list) { 
        int width = 0; 
        for (int i=0;i<choices.length;i++){ 
         if (width < textFont.getAdvance(choices[i].toString())){ 
          width = textFont.getAdvance(choices[i].toString()); 
         } 
        } 
        return width; 
       } 
      }; 
      listField.setFont(textFont); 
      for (int i=0;i<choices.length;i++){ 
       listField.insert(i, choices[i]); 
      } 
      add(listField); 
     } 
     protected boolean navigationClick(int status, int time) { 
      clicked(); 
      closed(); 
      return super.navigationClick(status, time); 
     } 
     protected boolean keyChar(char c, int status, int time) { 
      if (c == Characters.ENTER){ 
       clicked(); 
       closed(); 
      }else if (c == Characters.ESCAPE){ 
       closed(); 
      } 
      return super.keyChar(c, status, time); 
     } 
     protected void clicked(){ 
      try{ 
       selectedIndex = listField.getSelectedIndex(); 
       chooseField.setLabel(choices[selectedIndex].toString()); 
       ChoiceField.this.invalidate(); 
       if (fieldChangeListener != null){ 
        fieldChangeListener.fieldChanged(ChoiceField.this, selectedIndex); 
       } 
      }catch (ArrayIndexOutOfBoundsException e) { 
      } 
     } 
     protected void closed(){ 
      UiApplication.getUiApplication().invokeAndWait(new Runnable() { 
       public void run() { 
        try { 
         UiApplication.getUiApplication().popScreen(PopUpList.this); 
        }catch(Exception e){ 
        } 
       } 
      }); 
     } 
    } 
} 
1

.... fieldChangeを()メソッド..... OnCloseの()メソッドを呼び出します。

protected boolean onClose(){ 
uiapplication.getUiapplication.popScreen(this); 
return true; 
}