2011-03-13 62 views
0

我已經創建了我自己的自定義彈出屏幕,現在我試圖添加一個editfield,一切似乎都很好,但問題是我無法在編輯字段中編寫任何東西將Editfield添加到彈出屏幕

class sveetIt extends PopupScreen implements FieldChangeListener, DialogClosedListener { 

    Hashtable pitemData; 
    ButtonField sveetNowlabelField; 
    ButtonField sveetLaterlabelField; 
    WatingScreen watingScreen; 
    long scheduledTime; 
    Dialog updateDialog; 

    public sveetIt() { 
     super(new MyCustimGridFieldManager()); 
      LabelField messageLabelField = new LabelField("Enter your Sveet Message:",Field.FIELD_HCENTER) { 
      protected void paint(Graphics graphics) { 
       graphics.setColor(Color.YELLOWGREEN); 
       super.paint(graphics); 
      } 
     }; 
    EditField sveetTexteditField= new EditField(null, "Sveet Message", 50, EditField.FIELD_HCENTER 
        | EditField.FIELD_VCENTER 
        | EditField.NON_SPELLCHECKABLE | EditField.NO_NEWLINE); 
     VerticalFieldManager buttonVFManager = new VerticalFieldManager(VerticalFieldManager.FIELD_HCENTER); 
     HorizontalFieldManager hfManager = new HorizontalFieldManager(); 
     sveetNowlabelField = new ButtonField("Sveet Now"); 
     sveetLaterlabelField = new ButtonField("Sveet Later"); 
     sveetNowlabelField.setChangeListener(this); 
     sveetLaterlabelField.setChangeListener(this); 
     add(messageLabelField); 
     add(sveetTexteditField); 
     hfManager.add(sveetNowlabelField); 
     hfManager.add(sveetLaterlabelField); 
     buttonVFManager.add(hfManager); 
     add(buttonVFManager); 
    } 
    public boolean isEditable() { 
     return true; 
    } 

    protected boolean keyChar(char c, int status, int time) { 
     boolean retVal = false; 

     if (c == Characters.ESCAPE) { 
      Ui.getUiEngine().popScreen(this); 
      retVal = super.keyChar(c, status, time); 

     } 
     return retVal; 
    } 

    public void fieldChanged(Field field, int context) { 
     if (sveetNowlabelField == field) {   

      //Here directly starts uploading file 
      beginUpload(); 
     } else if (sveetLaterlabelField == field) { 
      // first picks up time when to upload 
      scheduledTime = getScheduleTime(); 
      if(scheduledTime!=1L) { 
       //now begins uploading file 
       beginUpload(); 
      } 
    }} 

    class SubscribingThread extends StoppableThread { 
     int network = 50; 

     public void run() { 

     } 
    } 

    public void beginUpload() { 
     try { 
      watingScreen = new WatingScreen("Uploading Sveet..."); 
      /* 
      * UiApplication.getUiApplication().invokeAndWait(new Runnable() { 
      * public void run() { Ui.getUiEngine().pushScreen(watingScreen); } 
      * }); 
      */ 
      BaseScreen.pushScreen(watingScreen); 
      Thread thread = new Thread(new Runnable() { 
       public void run() { 
        uploadToServer(); 
       } 
      }); 
      thread.start(); 
      // uploadToServer(); 
     } catch (Exception e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } finally { 

     } 
    } 

    private long getScheduleTime() { 
     scheduledTime = 0; 
     final DateTimePicker datePick = DateTimePicker.createInstance(); 
     UiApplication.getUiApplication().invokeAndWait(new Runnable() { 
      public void run() { 
       // TODO Auto-generated method stub 
       Calendar currentCalendar = datePick.getDateTime(); 
       datePick.setMinimumDate(currentCalendar); 
       datePick.doModal(); 
       Calendar cal = datePick.getDateTime(); 
       if (cal.after(currentCalendar)) { 
        Date date = cal.getTime(); 
        Dialog.alert("You selected " + date.toString()); 
        scheduledTime = date.getTime(); 
       } else { 
        Dialog.alert("Invalid date selection"); 
        scheduledTime = 1L; 
       } 
      } 
     }); 

     System.out.println("date in MilliSeconds is:" + scheduledTime); 
     return scheduledTime; 
    } 

public void uploadToServer() { 

    } public void dialogClosed(Dialog arg0, int arg1) { 

    } 
} 

class MyCustimGridFieldManager extends VerticalFieldManager { 

    public MyCustimGridFieldManager() { 
     super(VERTICAL_SCROLL | USE_ALL_WIDTH | FIELD_HCENTER); 
    } 

    protected void paint(Graphics gr) { 
     super.paint(gr); 
    } 

} 

回答

0

試試這個:

protected boolean keyChar(char c, int status, int time) { 


    if (c == Characters.ESCAPE) { 
     Ui.getUiEngine().popScreen(this);   

    } 

    return super.keyChar(c, status, time); 
} 
0

嘗試增加Field.EDITABLE你的風格的EditField中。

+0

我嘗試了類似的東西,我應該工作,我會測試它讓你知道。感謝您的回覆 – 2011-03-15 13:07:28