×

Discussion Board

Results 1 to 12 of 12
  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    24

    TextField OK Command

    Is it possible to replace the OK button for text fields. As it stands the user enters a number into the text field and then presses OK and then has to select the submit command. I was wondering if it were possible to set it up so when the user presses ok it runs the same code which it would have if the user selects the submit command. I tried using the setDefaultCommand() which is inherited from Item but it did nothing happens. Anyone have any ideas/suggestions?

  2. #2
    Regular Contributor
    Join Date
    Nov 2009
    Posts
    127

    Re: TextField OK Command

    Quote Originally Posted by am11 View Post
    Is it possible to replace the OK button for text fields. As it stands the user enters a number into the text field and then presses OK and then has to select the submit command. I was wondering if it were possible to set it up so when the user presses ok it runs the same code which it would have if the user selects the submit command. I tried using the setDefaultCommand() which is inherited from Item but it did nothing happens. Anyone have any ideas/suggestions?
    Hi,
    Actually i dint got your point what are you trying to do.
    please make it clear.

  3. #3
    Registered User
    Join Date
    Jan 2010
    Posts
    24

    Re: TextField OK Command

    -----------
    Last edited by am11; 2010-02-12 at 16:35. Reason: double post

  4. #4
    Registered User
    Join Date
    Jan 2010
    Posts
    24

    Re: TextField OK Command

    Sorry for my poor explanation. I have a form in which i have a text field. The user presses the edit button that appears when the focus is on the TextField and then enters a number into the text field. Once the user is finished entering the number the user presses the OK button and then presses the submit button to complete the task. I was wondering if it were possible to eliminate the need to press the submit button. So that once the user has entered the number and pressed the OK button on the TextField to confirm their entry to automatically submit the number once they press OK rather then needing then needing them to go that extra step and press the submit button. So essentially I want to replace the OK button or execute some code when the user presses the OK button as pressing the ok button is the signal that the user has finished entering the number. It seems like a minor issue however test users have found it quite annoying and redundant that they have to press OK and then submit rather then it being one action. If thats still not clear just ask again and ill try explain it further.

  5. #5
    Regular Contributor
    Join Date
    Nov 2009
    Posts
    127

    Re: TextField OK Command

    Hi,
    I got your point i want to know whether ok and submit button are string items or commands?
    You can place your code here so that i can help you out with the answer

  6. #6
    Regular Contributor
    Join Date
    Dec 2008
    Posts
    58

    Re: TextField OK Command

    I know what you mean. That happens in touch devices with no QWERTY.
    Can you tell us what is the device youre using and place a sample of your code?

  7. #7
    Registered User
    Join Date
    Jan 2010
    Posts
    24

    Re: TextField OK Command

    Im using Sony Ericsson W995. The code is attached.

    Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package Reader;
    
    import Menus.RecentSearches;
    import javax.microedition.lcdui.Command;
    import javax.microedition.lcdui.CommandListener;
    import javax.microedition.lcdui.Displayable;
    import javax.microedition.lcdui.Form;
    import javax.microedition.lcdui.Item;
    import javax.microedition.lcdui.ItemCommandListener;
    import javax.microedition.lcdui.TextField;
    
    /**
     *
     * @author Fayyaz
     */
    public class TextEntry extends Form implements CommandListener, ItemCommandListener {
    
        private Command enter;
        private Command scan;
        private Command mainMenu;
        private TextField barcodeEntry;
        private Product p;
        private String barcode;
        public volatile boolean visible = false;
    
        public TextEntry() {
            super("Barcode Scanner");
            enter = new Command("Enter",Command.ITEM,0);
            scan = new Command("Scanner",Command.ITEM,2);
            mainMenu = new Command("Main Menu",Command.BACK,0);
            barcodeEntry = new TextField("Enter a valid EAN-13, EAN-8, UPC-A or UPC-E Barcode:","", 13, TextField.NUMERIC);
            barcodeEntry.setDefaultCommand(enter);
            barcodeEntry.setItemCommandListener(this);
            append(barcodeEntry);
            addCommand(enter);
            addCommand(scan);
            addCommand(mainMenu);
            setCommandListener(this);
    
        }
    
        public void commandAction(Command c, Displayable d) {
    
            if(c == scan) {
                visible = false;
                Application.startScanner();
            }
            else if(c == enter) {
                barcode = barcodeEntry.getString().trim();
    
                if(barcode.length() != 13 || barcode.length() != 12 || barcode.length() != 8) {
                    Application.showError("Invalid Barcode. Please enter a valid EAN-13, EAN-8, UPC-A and UPC-E barcode.");
                }
    
                boolean valid = BarcodeReader.isValid(barcode);
    
                if(valid) {
                    p = new Product();
                    p.setBarcode(barcode);
                    RecentSearches.add(p);
                    Application.displayProduct(p);
                }
                else {
                    Application.showError("Invalid Barcode. Please enter a valid EAN-13, EAN-8, UPC-A and UPC-E barcode.");
                }
            }
            else if(c == mainMenu) {
                Application.mainMenu();
            }
        }
    
        public void commandAction(Command c, Item i) {
    
            if(c == enter) {
                barcode = barcodeEntry.getString().trim();
    
                if(barcode.length() != 13 || barcode.length() != 12 || barcode.length() != 8) {
                    Application.showError("Invalid Barcode. Please enter a valid EAN-13, EAN-8, UPC-A and UPC-E barcode.");
                }
    
                boolean valid = BarcodeReader.isValid(barcode);
    
                if(valid) {
                    p = new Product();
                    p.setBarcode(barcode);
                    RecentSearches.add(p);
                    Application.displayProduct(p);
                }
                else {
                    Application.showError("Invalid Barcode. Please enter a valid EAN-13, EAN-8, UPC-A and UPC-E barcode.");
                }
            }
        }
    
    }

  8. #8
    Regular Contributor
    Join Date
    Dec 2008
    Posts
    58

    Re: TextField OK Command

    I dont think its possible to replace the "OK" label. I sugest you to use canvas and make your own Textfield.
    Try using LWUIT, its an easy way to make canvas midlets. Theres a lot of components, like forms, tabs, tables, labels, etc.


    https://lwuit.dev.java.net/
    http://java.sun.com/developer/techni...e/lwuit_intro/

  9. #9
    Registered User
    Join Date
    Jan 2010
    Posts
    24

    Re: TextField OK Command

    I don't exactly want to replace the Ok label. I want a method to be called whenever the user presses the ok button. Is this possible without having to make my own textbox

  10. #10
    Regular Contributor
    Join Date
    Jul 2009
    Posts
    81

    Re: TextField OK Command

    Hi,
    When are you working on high level api , most of the thing what displaying and behaving is phone dependent . You can't change that.

    Thanks

  11. #11
    Regular Contributor
    Join Date
    Nov 2009
    Posts
    127

    Re: TextField OK Command

    Hi,

    It is not possible to change it you will have to use canvas there is no other rule.

    Thanks

  12. #12
    Registered User
    Join Date
    Jul 2010
    Posts
    1

    Re: TextField OK Command

    Hi am11!

    I was just wondering how you went about solving this problem with the OK default command for TextField? I am having the same problem now (using a TextField as a search field and I need to perform the search() once the OK or Enter key is pressed) and I don't think I can afford to use a canvas instead (I also have other custom items in the same form where I use this textfield) nor a different UI toolkit altogether. Were you able to find another workaround/solution to your problem?

    Thanks very much. Your reply will be greatly appreciated.

    Regards,
    Marco

Similar Threads

  1. HBufC::NewL(1) leaves why?
    By maildavebudd in forum Symbian
    Replies: 7
    Last Post: 2009-12-13, 05:17
  2. app terminates on 'EikStart::RunApplication'
    By Canellas in forum Symbian
    Replies: 2
    Last Post: 2009-10-08, 16:56
  3. Remove TextField "123" command from Menu
    By polys in forum Mobile Java General
    Replies: 7
    Last Post: 2009-07-21, 10:47
  4. Replies: 7
    Last Post: 2009-03-21, 18:54
  5. nokia 7210 modem via IR doesn't work !
    By oussamaaiadi in forum PC Suite API and PC Connectivity SDK
    Replies: 1
    Last Post: 2003-03-06, 10:46

Posting Permissions

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