×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    17

    help::user input using textbox

    Hello all.
    Its been a day I could build a java app that can run in mobile set. It was a simple hello world. Then I tried to take input from user using text box, and then alert the message. For the first time input it worked fine. But for the second time of input, it really did not work. The problem was, when I input for the first time, the alert showed the input message, but for the second input, I got the same alert that was input at first. What might be the problem?
    I tried the same with the log in form for IDE. The problem was the same. Here is the code for Log in.
    I did all in NetBeans IDE, so I could not figure out whether the below code could help in determining the problem. Because there are a lot of codes.
    Anyway, these are a part of code that I copied and pasted.

    Code:
        public TextField getTextField() {
            if (textField == null) {
                // write pre-init user code here
                textField = new TextField("Input", null, 32, TextField.ANY);
                textField.setLayout(ImageItem.LAYOUT_DEFAULT);
                textField.setPreferredSize(-1, -1);
                // write post-init user code here
            }
            return textField;
        }
    
    
        public Alert getAlert() {
            if (alert == null) {
                // write pre-init user code here
                alert = new Alert("alert");
                alert.setTimeout(Alert.FOREVER);
                // write post-init user code here
                String username = loginScreen.getUsername();
                String password = loginScreen.getPassword();
                String message = "You entered username as "+username+" and password as "+password;
                alert = new Alert("Hello",message,null,null);
                alert.setTimeout(Alert.FOREVER);
            }
            return alert;
        }
    There is an OK button. When i press OK button, it transfers to alert where the string of text box is taken and displayed.
    Last edited by bunkdeath; 2010-08-23 at 04:45.

  2. #2
    Registered User
    Join Date
    Aug 2010
    Posts
    23

    Re: help::user input using textbox

    Hi,
    sure this alert will always give you the first entered values, since you added your code at the end of (if alert==null), which will happen only once, the other times, the alert will no more be null after its initialization, so the required is to place them before the return and your code will be like this:

    public Alert getAlert() {
    if (alert == null) {
    // write pre-init user code here
    alert = new Alert("alert");
    alert.setTimeout(Alert.FOREVER);
    // write post-init user code here
    }/*
    }
    return alert;
    }
    //</editor-fold>
    */
    String username = loginScreen.getUsername();
    String password = loginScreen.getPassword();
    String message = "You entered username as "+username+" and password as "+password;
    alert = new Alert("Hello",message,null,null);
    alert.setTimeout(Alert.FOREVER);
    return alert;
    }

    try it, it will work!!
    Regards.

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    17

    Re: help::user input using textbox

    Thank you ZeinaShehab for your reply!!! It really worked!! I did not noticed about that.

    Thank you again.

Similar Threads

  1. Input text to TextBox
    By contra3385 in forum Symbian
    Replies: 20
    Last Post: 2009-09-29, 09:37
  2. Correct input textbox.
    By elviin in forum Symbian User Interface
    Replies: 2
    Last Post: 2009-06-16, 04:49
  3. Input Textbox problem in Widget
    By neha.chauhan@kleward.com in forum Symbian
    Replies: 0
    Last Post: 2008-08-27, 16:32
  4. Replies: 2
    Last Post: 2006-10-26, 09:41
  5. About Input method of TextBox/TextField .
    By akokchai in forum Mobile Java General
    Replies: 1
    Last Post: 2003-02-24, 11:10

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •