×

Discussion Board

Results 1 to 7 of 7

Thread: TextField

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    5

    TextField

    If You want to make a TextField with calculator
    (only adding and 1 number, if you press on 5 it
    show 5 then 6 it show 11 then 3 it show 14 aso)
    and then use this code

    int oldnumber =0;

    public void itemStateChanged(Item item){
    if (item instanceof TextField){
    TextField text=(TextField)item;
    int newNumber=oldNumber+Integer.parseInt(text.getString().substring(text.getString().length()-1,text.getString().length()));
    oldnumber=newnumber;
    text.setString(""+newNumber);
    so works it with Suns emulator but not in Nokia 6630. Why?

  2. #2
    Nokia Developer Expert
    Join Date
    Aug 2007
    Posts
    1,595

    Re: TextField

    Hello onestep,

    and welcome to Forum Nokia Discussion Boards!

    so works it with Suns emulator but not in Nokia 6630. Why?
    What happens with Nokia 6630?

    Regards,
    r2j7
    [URL="http://library.forum.nokia.com/java"][B] >>> Java Developer's Library <<<[/B][/URL]
    [URL="https://www.developer.nokia.com/Resources/Support/Technical_support.xhtml"] [B]>>> Technical Support for Java ME development <<<[/B][/URL]
    [URL="https://publish.ovi.com/info/"][B]>>> Nokia Publish: reach millions of Nokia users worldwide through Nokia Store <<<[/B][/URL]

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

    Re: TextField

    nothing happens it only shows 0, but it must be the code
    int newNumber=oldNumber+Integer.parseInt(text.getString().substring(text.getString().length()-1,text.getString().length()));
    that the phone dont accept.

  4. #4
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: TextField

    public void itemStateChanged(Item item){
    if (item instanceof TextField){
    TextField text=(TextField)item;
    int newNumber=oldNumber+Integer.parseInt(text.getString().substring(text.getString().length()-1,text.getString().length()));
    oldnumber=newnumber;
    text.setString(""+newNumber);
    Hey do one thing, draw the value of the oldnumber using the form.append(""+oldnumber);just for the testing.
    And paint the output on the console after oldnumber=newnumber; and before this line.Check and let's us know the results.
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  5. #5
    Registered User
    Join Date
    May 2010
    Posts
    5

    Re: TextField

    With form.append(""+oldnumber) it only show 0 on the phone, but in the emulator it adds ok.
    But I have this code for the TextField
    public TextField getTextField() {
    if (textField == null) {

    textField = new TextField("tf", null, 32, TextField.NUMERIC);
    textField.setString(""+0);
    }
    return textField;
    }
    and if I take +0 away from the textField.setString(""+0); the phone works but only with one number, if I add nr 1 it show 1 but when I add next number it shows 2 and that do it if I add nr5,nr0 or all the numbers.The phone has his own loop
    This loop
    Nr1 1+1+2+4+8+6+2+4+8+6 aso
    Nr2 2+2+4+8+6+2+4+8 aso
    Nr3 3+3+6+2+4+8+6+2 aso
    Nr4 4+4+8+6+2+4+8+6 aso
    Nr5 5+5+0+0+0 aso
    Nr6 6+6+2+4+8+6 same loop as nr 1, Nr7 start with two 7 and then the same loop as nr 2
    Nr8 has Nr3s loop and number nr 9 has nr 4s loop, if I start adding with a zero it shows only 0 and it is no matter which number I add.

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    5

    Re: TextField

    I try with form.append(""+oldnumber) and textField.setString("");
    and it show exact the same loops.

  7. #7
    Registered User
    Join Date
    May 2010
    Posts
    5

    Re: TextField

    Is it only Nokia 6630 which behave so strange.
    if I change
    int newNumber=oldNumber+Integer.parseInt(text.getString().substring(text.getString().length()-1,text.getString().length()));
    oldnumber=newnumber;
    text.setString(""+newNumber);
    to
    int newNumber=Integer.parseInt(text.getString().substring(text.getString().length()-1,text.getString().length()));
    int ANumber=newNumber;
    int BNumber=ANumber+oldNumber;
    oldnumber=BNumber;
    text.setString(""+BNumber);
    so works it in the emulator but in the phone its the same strange loops.
    but if I change to
    int ANumber=newNumber*0+1;
    then it adds +1 both in the emulator and in the phone.

Similar Threads

  1. Replies: 1
    Last Post: 2010-03-07, 15:32
  2. TextField problem
    By thanhvinh0906 in forum Mobile Java General
    Replies: 3
    Last Post: 2009-10-08, 19:24
  3. Problem of TextField key hooking...
    By raselbd in forum Mobile Java General
    Replies: 3
    Last Post: 2008-09-02, 08:21
  4. TextField in DECIMAL: Compatibility problems with some phones?!?
    By D0X-Dr in forum Mobile Java Tools & SDKs
    Replies: 12
    Last Post: 2008-01-11, 10:08
  5. TextField refresh problem with Nokia devices
    By RalfHupfer in forum Mobile Java General
    Replies: 1
    Last Post: 2004-07-02, 01:35

Posting Permissions

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