×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Regular Contributor
    Join Date
    Nov 2010
    Posts
    118

    Alert Thread PLEASE HELP

    hi...i have a textbox to create a msg. if textbox caretPosition==5 ,i want to display an alert.
    this is my code:

    Code:
    public void Create() //CREATE MESSAGE METHOD
        {
           currentMenu = "Create Message";
           String message = "";
           msg = new TextBox("Create Message", message, 20, TextField.ANY);
           checkCaret(msg);
           msg.addCommand(cancelCommand);
           msg.addCommand(enter_phoneCommand);
           msg.addCommand(clearCommand);
           msg.addCommand(saveCommand);
           msg.setCommandListener(this);
           display.setCurrent(msg);
           resumeScreen = msg;
        }
    
        public void checkCaret(final TextBox msg)
        {
            Thread x=new Thread()
            {
                public void run()
                {
                    if(msg.getCaretPosition()==5)
                    {
                        Alert as=new Alert("ASASA");
                        display.setCurrent(as);
                    }
                }
            };
            x.start();
            
        }
    please help me...thanks

  2. #2
    Regular Contributor
    Join Date
    Nov 2010
    Posts
    118

    Re: Alert Thread PLEASE HELP

    can anyone help me?

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

    Re: Alert Thread PLEASE HELP

    Quote Originally Posted by binsint View Post
    can anyone help me?
    PHP Code:
    public void run() {
            
    // TODO Auto-generated method stub
            
    while (true) {
                if (
    textBox.getCaretPosition() == 5) {
                    
    Alert as = new Alert("ASASA");
                    
    display.setCurrent(as);
                }

            }

        } 
    Last edited by raj_J2ME; 2011-02-09 at 07:15. Reason: Corerction in reply...
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  4. #4
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: Alert Thread PLEASE HELP

    Quote Originally Posted by binsint View Post
    hi...i have a textbox to create a msg. if textbox caretPosition==5 ,i want to display an alert.
    this is my code:

    Code:
    public void Create() //CREATE MESSAGE METHOD
        {
           currentMenu = "Create Message";
           String message = "";
           msg = new TextBox("Create Message", message, 20, TextField.ANY);
           checkCaret(msg);
           msg.addCommand(cancelCommand);
           msg.addCommand(enter_phoneCommand);
           msg.addCommand(clearCommand);
           msg.addCommand(saveCommand);
           msg.setCommandListener(this);
           display.setCurrent(msg);
           resumeScreen = msg;
        }
    
        public void checkCaret(final TextBox msg)
        {
            Thread x=new Thread()
            {
                public void run()
                {
                    if(msg.getCaretPosition()==5)
                    {
                        Alert as=new Alert("ASASA");
                        display.setCurrent(as);
                    }
                }
            };
            x.start();
            
        }
    please help me...thanks
    Even after using Thread you are checking if(msg.getCaretPosition()==5) only once; you need to check this In a loop...with a sleep of some 100ms as under:
    Code:
    public void checkCaret(final TextBox msg)
        {
            Thread x=new Thread()
            {
                public void run()
                {
                   boolean repeat=true;
                   do while(repeat){
                   if(msg.getCaretPosition()==5)
                    {
                        repeat=false;
                        Alert as=new Alert("ASASA");
                        display.setCurrent(as);
                    }
                    This.sleep(100); // may require try catch() block
                    }
                }
            };
            x.start();
            }
    thanks,
    ~Amitabh
    (Champion of the Month -Aug'13)
    Follow me on my blog for Innovative Mobile Apps

  5. #5
    Regular Contributor
    Join Date
    Nov 2010
    Posts
    118

    Re: Alert Thread PLEASE HELP

    hi raj! it worked... here's what i did: THANKS



    Code:
    public void checkCaret(final TextBox msg)
        {
            Thread x=new Thread()
            {
                public void run()
                {
                    
                    while(check_caret)
                    {
                        try
                        {
                            if(msg.size() == 161)
                            {
                                Alert as = new Alert(null,"160 Characters exceeded!",null,AlertType.INFO);
                                as.addCommand(ok1Command);
                                as.setTimeout(Alert.FOREVER);
                                display.setCurrent(as);
                                check_caret = false;
                            }
                        }
                        catch(IllegalArgumentException e)
                        {
                        }
                   }
                }
            };
            x.start();
        }
    Last edited by binsint; 2011-02-09 at 16:13.

  6. #6
    Regular Contributor
    Join Date
    Nov 2010
    Posts
    118

    Re: Alert Thread PLEASE HELP

    hi... if i use this checkCaret() function my SMS listener is not listening... maybe because this function is a thread too? how can i run both of the threads together? the thread in my getCaret() and my SMS listener thread? please help..thanks

  7. #7
    Regular Contributor
    Join Date
    Nov 2010
    Posts
    118

    Re: Alert Thread PLEASE HELP

    anyone can help? thanks

Similar Threads

  1. Please Help! How to use Alert message with YES|NO commands
    By chatrapati.nokia.santhosh in forum Mobile Java General
    Replies: 2
    Last Post: 2009-10-19, 08:37
  2. Help Please..about thread!!!
    By kilofs in forum Mobile Java General
    Replies: 1
    Last Post: 2007-11-11, 08:44
  3. Custom Alert Component Please Help!!!!!!
    By HidayathKhan in forum Symbian
    Replies: 2
    Last Post: 2007-10-25, 15:05
  4. Please help me in Thread concept
    By kannabiran.krish in forum Symbian
    Replies: 3
    Last Post: 2007-08-23, 14:04
  5. please help... thread & active scheduler
    By suzuk in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2004-06-09, 14:43

Posting Permissions

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