Adding Editfield to Popup screen

Deadly 提交于 2019-12-25 03:44:22

问题


I have created my own custom popup screen to which now I am trying to add a editfield , everything seems to be fine but the problem is that I am not able to write anything in the edit field

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);
    }

}

回答1:


try this:

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


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

    }

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



回答2:


Try adding Field.EDITABLE to your style for the EditField.



来源:https://stackoverflow.com/questions/5288770/adding-editfield-to-popup-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!