×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Regular Contributor
    Join Date
    Oct 2008
    Posts
    121

    Ask user permission while doing some process in loop

    Hi All,

    I wanted to ask user permission while doing a process in loop.

    Code:
    loop
      ask user permission. (needs UI)
    end loop
    I tried to use alert (type FOREVER) here but it doesnt stops in between for asking user permission. The Display is being overwritten by the last Alert display in loop.

    How can we have modal prompt to user in a loop for each iteration?

    Please provide some suggestions.

    Thanks,
    Sandeep

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Ask user permission while doing some process in loop

    You need to think in an event driven way. Use the commandAction event from the Alert to trigger the action. There are no modal dialogues in J2ME.

    Graham.

  3. #3
    Regular Contributor
    Join Date
    Oct 2008
    Posts
    121

    Re: Ask user permission while doing some process in loop

    Hi Graham,

    Thanks for your reply. As far as i understand, we don't have to set next display object till we take input from user. We need to create modal dialogs by having logic so that display object is not overwritten.

    Regards,
    Sandeep

  4. #4
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Ask user permission while doing some process in loop

    There is no dialogue that will block the code until there is input. Such a user interface component does not exist. Structuring your code as a loop of this kind will not work.

    Display the first Alert. Use the commandAction() event of the Alert's CommandListener to perform the action (assuming the Command is "yes"). At the end of performing the action, display the next Alert (setCurrent()).

    Something like:

    Code:
    private static final Command acceptCommand = new Command(...);
    private static final Command rejectCommand = new Command(...);
    
    private int limit;
    private int counter;
    private Alert confirmationAlert;
    
    public void start() {
        counter = 0;
        limit = ...;
        confirmationAlert = new Alert(...);
        confirmationAlert.addCommand(acceptCommand);
        confirmationAlert.addCommand(rejectCommand);
        confirmationAlert.setCommandListener(this);
        display.setCurrent(confirmationAlert);
    }
    
    public void commandAction(Command c, Displayable d) {
        if (c == acceptCommand) {
            doConfirmedAction();
        }
    
        counter++;
        if (counter < limit) {
            display.setCurrent(confirmationAlert);
        } else {
            display.setCurrent(nextScreen);
        }
    }
    Graham.

Similar Threads

  1. Connect as master with N82?
    By mikrodidakt1 in forum Bluetooth Technology
    Replies: 5
    Last Post: 2009-05-01, 11:09
  2. s40 versions support background process without user notification?
    By kanchan sinha in forum Mobile Java General
    Replies: 3
    Last Post: 2008-02-15, 18:11
  3. a question about the user agent string
    By jackchang1@gmail.com in forum Mobile Java General
    Replies: 3
    Last Post: 2005-09-19, 12:06
  4. Replies: 0
    Last Post: 2004-11-24, 18:49
  5. Replies: 0
    Last Post: 2003-09-24, 06: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
  •  
×