×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Regular Contributor
    Join Date
    Jan 2009
    Posts
    103

    How to get the Focus textbox data

    Hi all
    I am dispalying 4textbox how can i know which textbox is focused ??? and how can i get the focused textbox content ????
    code down in J2ME

    Regards
    Divya

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,085

    Re: How to get the Focus textbox data

    Please explain what are you trying to do, you may need to create a Custom Item for this where you get this by:
    protected boolean traverse(int dir, int viewportWidth, int viewportHeight, int[] visRect_inout)
    Called by the system when traversal has entered the item or has occurred within the item.
    protected void traverseOut()
    Called by the system when traversal has occurred out of the item.

    So to know which of your custome item is in focus you can set some variable in these methods.



    thanks,
    ~Amitabh
    Follow me on my blog for Innovative Mobile Apps

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    41

    Smile Re: How to get the Focus textbox data

    Let me see if I understood your question...

    I think the following:

    • When you to be running your application the textBox focused will stay more black than the others...
    • If you want to get the textBox focused content you can use the method 'yourTextBoxName.getContent'...


    I think to have helped you...

    if you have many doubts post here again....

    bye...

  4. #4
    Registered User
    Join Date
    Oct 2008
    Posts
    41

    Exclamation Re: How to get the Focus textbox data

    I thought more about this case...

    So I think you should using TextField, because TextBox is a displayable so You can not diplaying 4, but just one is possible. Now is using TextField You can use many...

    But you told TextBox...I made an example using too TextBox, where you can change of the one TextBox to another...


    import javax.microedition.lcdui.Command;
    import javax.microedition.lcdui.CommandListener;
    import javax.microedition.lcdui.Display;
    import javax.microedition.lcdui.Displayable;
    import javax.microedition.lcdui.TextBox;
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.midlet.MIDletStateChangeException;


    public class DoubleTextBoxTest extends MIDlet implements CommandListener {

    private Display display;
    private TextBox textBox1;
    private TextBox textBox2;
    private Command exit;
    private Command changeTextBoxCommand;

    public DoubleTextBoxTest() {
    display = Display.getDisplay(this);
    exit = new Command("Exit", Command.EXIT, 0);
    this.changeTextBoxCommand=new Command("ChangeTextBox", Command.OK, 1);
    textBox1=new TextBox("TextBox1", "press ChangeTextBox command for to change the current" +
    " textBox", 150, 0);
    textBox1.addCommand(exit);
    textBox1.addCommand(changeTextBoxCommand);
    textBox1.setCommandListener(this);
    textBox2=new TextBox("TextBox2", "press ChangeTextBox command for to change the current" +
    " textBox", 150, 0);
    textBox2.addCommand(exit);
    textBox2.addCommand(changeTextBoxCommand);
    textBox2.setCommandListener(this);

    }

    protected void startApp() throws MIDletStateChangeException {
    display.setCurrent(textBox1);
    }

    public void commandAction(Command command, Displayable d) {
    if (command == exit) {
    try {
    this.destroyApp(true);
    } catch (MIDletStateChangeException e) {
    e.printStackTrace();
    } finally {
    this.notifyDestroyed();
    }
    }

    if((d==textBox1) && (command==changeTextBoxCommand)){
    display.setCurrent(textBox2);
    }

    else if((d==textBox2) && (command==changeTextBoxCommand)){
    display.setCurrent(textBox1);
    }
    }

    protected void destroyApp(boolean arg0) throws MIDletStateChangeException {}

    protected void pauseApp() {}
    }



    Quote Originally Posted by valderind4 View Post
    Let me see if I understood your question...

    I think the following:

    • When you to be running your application the textBox focused will stay more black than the others...
    • If you want to get the textBox focused content you can use the method 'yourTextBoxName.getContent'...


    I think to have helped you...

    if you have many doubts post here again....

    bye...

  5. #5
    Regular Contributor
    Join Date
    Jan 2009
    Posts
    103

    Re: How to get the Focus textbox data

    Quote Originally Posted by valderind4 View Post
    I thought more about this case...

    So I think you should using TextField, because TextBox is a displayable so You can not diplaying 4, but just one is possible. Now is using TextField You can use many...

    But you told TextBox...I made an example using too TextBox, where you can change of the one TextBox to another...


    import javax.microedition.lcdui.Command;
    import javax.microedition.lcdui.CommandListener;
    import javax.microedition.lcdui.Display;
    import javax.microedition.lcdui.Displayable;
    import javax.microedition.lcdui.TextBox;
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.midlet.MIDletStateChangeException;


    public class DoubleTextBoxTest extends MIDlet implements CommandListener {

    private Display display;
    private TextBox textBox1;
    private TextBox textBox2;
    private Command exit;
    private Command changeTextBoxCommand;

    public DoubleTextBoxTest() {
    display = Display.getDisplay(this);
    exit = new Command("Exit", Command.EXIT, 0);
    this.changeTextBoxCommand=new Command("ChangeTextBox", Command.OK, 1);
    textBox1=new TextBox("TextBox1", "press ChangeTextBox command for to change the current" +
    " textBox", 150, 0);
    textBox1.addCommand(exit);
    textBox1.addCommand(changeTextBoxCommand);
    textBox1.setCommandListener(this);
    textBox2=new TextBox("TextBox2", "press ChangeTextBox command for to change the current" +
    " textBox", 150, 0);
    textBox2.addCommand(exit);
    textBox2.addCommand(changeTextBoxCommand);
    textBox2.setCommandListener(this);

    }

    protected void startApp() throws MIDletStateChangeException {
    display.setCurrent(textBox1);
    }

    public void commandAction(Command command, Displayable d) {
    if (command == exit) {
    try {
    this.destroyApp(true);
    } catch (MIDletStateChangeException e) {
    e.printStackTrace();
    } finally {
    this.notifyDestroyed();
    }
    }

    if((d==textBox1) && (command==changeTextBoxCommand)){
    display.setCurrent(textBox2);
    }

    else if((d==textBox2) && (command==changeTextBoxCommand)){
    display.setCurrent(textBox1);
    }
    }

    protected void destroyApp(boolean arg0) throws MIDletStateChangeException {}

    protected void pauseApp() {}
    }
    actually i am using 4 textbox of high level component so i want to clear the content of the textbox that is focused how shall i do this

  6. #6
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,085

    Re: How to get the Focus textbox data

    Hi Divya,

    Try LWUIT, check the LWUIT API document you can get these events in LWUIT and do it easy.
    In LWUIT TextArea which is same as MIDP TextBOX you get to addFocusListener and work with it to clear the text area when it is focused.



    thanks,
    ~Amitabh
    Follow me on my blog for Innovative Mobile Apps

Similar Threads

  1. SIP calls over Packet data
    By thefamilyman in forum VoIP
    Replies: 8
    Last Post: 2010-04-27, 06:12
  2. Replies: 2
    Last Post: 2006-08-11, 20:51
  3. Replies: 0
    Last Post: 2006-06-05, 18:08
  4. Replies: 2
    Last Post: 2004-09-15, 22:47
  5. Internet Access Config via Smart Message
    By ajbrindley in forum Smart Messaging
    Replies: 1
    Last Post: 2002-08-14, 07:56

Posting Permissions

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