2012-01-04 65 views
0

我創建了我自己的簡單ChoiceField通過延長ObjectChoiceField ..這就像..如何創建自定義Choicefield的彈出窗口並調用它?

public class MyChoiceField extends ObjectChoiceField 
{ 

    public MyChoiceField(String label ,Object[] choices) 
    { 
     super(label, choices); 
    } 

    protected void layout(int width, int height) 
    { 
     setMinimalWidth(width/2-62); 
     super.layout(width, height); 
    } 

    public void paint(Graphics graphics) 
    { 
     super.paint(graphics); 
    }  
} 

現在我想,當我在自定義菜單(不是默認的彈出窗口,黑莓提供時選擇MyChoiceField以顯示我的選擇用戶點擊ChoiceField)..

我該如何實現它?示例代碼將很可觀.. 感謝

回答

0

嘗試重寫方法fieldChangeNotify(int context)ObjectChoiceField這樣的:

public class MyChoiceField extends ObjectChoiceField 
{ 

    public MyChoiceField(String label ,Object[] choices) 
    { 
     super(label, choices); 
    } 

    protected void layout(int width, int height) 
    { 
     setMinimalWidth(width/2-62); 
     super.layout(width, height); 
    } 

    protected void fieldChangeNotify(int context) { 

     int index = getSelectedIndex(); 

     try{ 
      VerticalFieldManager vfm = new VerticalFieldManager(); 

      vfm.add(new LabelField("[Pop Up Content]\nChoice Field Changed #\n"+choices[index]+" selected.")); 

      PopupScreen popUpScreen = new PopupScreen(vfm){ 
       public boolean onClose() 
       { 
        this.close(); 
        return true; 
       } 
      }; 

      UiApplication.getUiApplication().pushScreen(popUpScreen); 

     } catch(Exception exc) { 
      System.out.println("Exception in choiceField fieldChangeNotify"); 
     } 
    } 

    public void paint(Graphics graphics) 
    { 
     super.paint(graphics); 
    } 
} 

使用MyChoiceField現在有點像這樣:

String[] choices; // Keep This Global 
VerticalFieldManager vfm = new VerticalFieldManager(Manager.FIELD_VCENTER);    
choices = new String[2]; 
choices[0] = new String("Choice1"); 
choices[1] = new String("Choice2"); 
vfm.add(new MyChoiceField("Choise", choices)); 

讓我知道這個解決方案是否有效。

+0

不知道你想通過'下拉彈出'的意思...可能是你想要的意思是選擇列表。通過你的說法「我想創建一個新的'彈出'」--- ---我不明白你想製作一個定製彈出式屏幕。我認爲「當我選擇MyChoiceField時調用彈出窗口」是你想要做的主要事情,而且我確信我提供的代碼完全是這樣。 – 2012-01-04 07:52:20

+0

我想要我的應用程序顯示我自己的彈出窗口,當我點擊Choicefield。比如當我們選擇性別的choicefield時,我想在彈出窗口中顯示男性和女性的選項。黑莓手機有可能嗎? – 2012-01-04 07:58:54

+0

喜歡,www.facebook.com的生日。我想用我自己的設計展示jan/feb/mar ...。是否有可能 – 2012-01-04 08:02:32