Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User Rahul More's Avatar
    Join Date
    Dec 2012
    Location
    Mumbai, Maharashtra, India
    Posts
    79
    I have created an Alert dialog box in my J2ME app to alert user when user press exit button to terminate an app & ask user confirmation to exit from app with yes and no command.when user press Yes button app will terminate and when user press No button app will return to its Main form. To do this I develop a code from scratch which are as follows :-

    Code:
    public class CustomAlert extends MIDlet implements CommandListener  
    {
            Alert ExitAlrt;
            Display d;
            Command MainListSelect, Exit, YesCmdAlrt, NoCmdAlrt;
            List MainList;
            
    	public CustomAlert()
    	{
                    d = Display.getDisplay(this);
    		
                    //Initialization of commands
    		MainListSelect = new Command("Select", Command.SCREEN, 1);
    		Exit = new Command("Exit", Command.STOP, 2);
                    
    		//Initialization of lists
    		MainList = new List("Menu", List.IMPLICIT);
                           
                    //Adding command to lists
    		MainList.addCommand(MainListSelect);
    		MainList.addCommand(Exit);
    		MainList.setCommandListener(this);
                    
                   //Appending the content of lists
    		MainList.append("Reminder List",null);
    		MainList.append("Settings",null);          
            }
        protected void startApp()
        {   
            MainList.setSelectedIndex(0, true);
            d.setCurrent(MainList);
        }
        protected void pauseApp() { }
        protected void destroyApp(boolean unconditional)
        {}
        
        public void commandAction(Command cmd,Displayable dispable) // This method handle commands which operate list that is Select & Exit
        {
            if(cmd == MainListSelect)
            {
                int slctindx = MainList.getSelectedIndex();
                if(slctindx == 0)
                {
                    
                }
                else if(slctindx == 1)
                {
                   
                } 
            }
           
             if(cmd == Exit)
            {
                ExitAlrt = new Alert("Application Alert","Are you sure you want to exit?",null, AlertType.WARNING);
                YesCmdAlrt = new Command("Yes", Command.EXIT,1);
                ExitAlrt.addCommand(YesCmdAlrt); 
                NoCmdAlrt = new Command("No", Command.SCREEN,2);
                ExitAlrt.addCommand(NoCmdAlrt);
                d.setCurrent(ExitAlrt);
            }
        }
        
        public void commandAction(Command cmd)  // This Code handle Commands present on Alert dialog box. 
        {
                ExitAlrt.setCommandListener(this);
                if(cmd == NoCmdAlrt)
                {
                    d.setCurrent(MainList);
                }
                else if(cmd == YesCmdAlrt)
                {   
                    destroyApp(true);
                    notifyDestroyed();
                }
         }
    }
    In above code problem is when I click on Exit button, Alert box appears & when I press Yes button to terminate an app it again redirect to me on Main List of an app...... I did lot of placements in code but problem remain constant....... I hope you understood my problem.... Now what is solution for this? I am still working on this.

  2. #2
    Nokia Developer Champion im2amit's Avatar
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    2,917
    ExitAlrt.setCommandListener(this);
    should be moved to the code block where you have defined ExitAlrt
    thanks,
    ~Amitabh
    (Poster of the Month -Dec'12)
    Follow me on my blog for Innovative Mobile Apps

  3. #3
    Registered User Rahul More's Avatar
    Join Date
    Dec 2012
    Location
    Mumbai, Maharashtra, India
    Posts
    79
    @ im2amit :- I did as per you said...... but after doing, program execution get blocked in alert dialog box and program doesn't respond to Yes- No commands of alert dialog box....... Then now????

  4. #4
    Registered User Rahul More's Avatar
    Join Date
    Dec 2012
    Location
    Mumbai, Maharashtra, India
    Posts
    79
    Is that possible to set another command Listener to listen command event of alert dialog box?????

  5. #5
    Nokia Developer Champion im2amit's Avatar
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    2,917
    yes,,

    Try using listener in an anonymous inner subclass like below for your Alert

    Command c = new Command("Exit", Command.EXIT, 0);
    d.addCommand(c);
    d.setCommandListener(new CommandListener() {
    public void commandAction(Command c, Displayable s) {
    notifyDestroyed();
    }
    });
    thanks,
    ~Amitabh
    (Poster of the Month -Dec'12)
    Follow me on my blog for Innovative Mobile Apps

  6. #6
    Registered User Rahul More's Avatar
    Join Date
    Dec 2012
    Location
    Mumbai, Maharashtra, India
    Posts
    79
    @im2amit :- Your suggestion works..........Now my app perfectly running as per my consideration......... Very Very Thanx a lot Amitabh Sir for your support and suggestions.....

Similar Threads

  1. Command Action for alert
    By vishal.vpb in forum Mobile Java General
    Replies: 12
    Last Post: 2011-08-22, 09:48
  2. Adding Command to an Alert
    By arungupta_2jan in forum Mobile Java General
    Replies: 2
    Last Post: 2009-05-11, 06:02
  3. Alert dialog
    By Asheesh in forum Symbian C++
    Replies: 1
    Last Post: 2004-11-02, 17:24
  4. Yes-No Confirmation Dialog using Alert
    By kakoskin in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2004-04-08, 15:48
  5. Alert with Command
    By wing0custom in forum Mobile Java General
    Replies: 1
    Last Post: 2003-11-03, 19:27

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved