BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 11-20-2007, 02:06 AM   #1 (permalink)
New Member
 
Join Date: Nov 2007
Model: 8800
PIN: N/A
Carrier: Nextel
Posts: 14
Post Thanks: 0
Thanked 0 Times in 0 Posts
Red face Request Save/Discard/Cancel

Please Login to Remove!

Hello folks!

Though it seems to be quite a basic thing I could not find a solution by searching the internet. I simply like to detect and use the choice the user made after the view/discard/cancel button appears, e.g. to initialize some actions after the user clicked on "save". How can I request the result of the choosen button?

I tried to use the DialogClosedListener interface with its dialogClosed method but it it didn't work. I tried it like this:

Code:
public class SampleScreen extends DialogClosedListener{

...

// screen fields
...

 public void  dialogClosed(Dialog dialog, int choice){

    if (choice ==  Dialog.DISCARD){
      System.out.println("discard");
    }
    else if(choice ==  Dialog.CANCEL){
      System.out.println("cancel");
    }
    else if(choice ==  Dialog.SAVE){
      System.out.println("save");
    }
    
    if (dialog.getSelectedValue() ==  Dialog.DISCARD){
      System.out.println("discard");
    }
    else if(dialog.getSelectedValue() ==  Dialog.CANCEL){
      System.out.println("cancel");
    }
    else if(dialog.getSelectedValue() ==  Dialog.SAVE){
      System.out.println("save");
    }
 }


}

Thanks for any suggestions!
Offline  
Old 11-20-2007, 03:09 AM   #2 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Code:
Object[] choices = new Object[] {"cancel", "exit", "to background" };
int result = Dialog.ask("really quit?", choices, 1);
switch (result) {
case 1:
System.exit(0);
case 2:
UiApplication.getApplication().requestBackground();
}
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 11-20-2007, 03:31 AM   #3 (permalink)
New Member
 
Join Date: Nov 2007
Model: 8800
PIN: N/A
Carrier: Nextel
Posts: 14
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Simon,

thanks for your answer. Actually I meant the standard dialog appearing after changes had been made in a screen and the user wants to leave the screen. Then the dialog "chages made" is displayed with the buttons "SAVE", "DISCARD" and "CANCEL". So I'd like to request the result of the choice the user made and use this data for doing something else. Any idea how to refer to that button pressed? On default it closes the screen when choosing "SAVE" or "DISCARD" and otherwise it stays in the screen.
Offline  
Old 12-03-2007, 08:27 PM   #4 (permalink)
New Member
 
Join Date: Nov 2007
Model: 8800
PIN: N/A
Carrier: Nextel
Posts: 14
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I found a solution, by overwriting the onSavePrompt method. Just replace it by your own dialog and handle the actions you wish to be done depending on the choice.
Offline  
Old 03-03-2008, 12:11 PM   #5 (permalink)
New Member
 
Join Date: Mar 2008
Model: 8310
PIN: N/A
Carrier: Orange
Posts: 4
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default in case someone needs the way to do it...

An actual way to do it would be to provide your own implementation for the whole thing.

//Create a class that implement the DialogClosedListener Interface
static final class myDialogListener implements DialogClosedListener {
public void dialogClosed(Dialog dialog, int choice){
switch (choice) {
case Dialog.DELETE : Status.show("Delete msg"); break;
case Dialog.OK : Status.show("OK msg"); break;
case Dialog.CANCEL : Status.show("Cancel msg"); break;
}
}
}


then, in your code where instanciating your custom dialog:

// Instanciation of custom Dialog
myDialog aDialog = new myDialog("Custom Dialog", tab1, tab2, 1, Bitmap.getPredefinedBitmap(Bitmap.QUESTION), Manager.FOCUSABLE);
aDialog.setDialogClosedListener(new myDialogListener());
aDialog.show();
Offline  
Old 03-03-2008, 02:51 PM   #6 (permalink)
CrackBerry Addict
 
Join Date: Jun 2005
Location: Manchester, UK
Model: BOLD
Carrier: t-mobile
Posts: 714
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

these all sound a far too complicated... just override the mainscreens method for save, i'll add a code snippet tomorrow if i remember, by default selecting cancel pops the dialog and discard calls close on the main screen and pops both your screen and the dialog. all you need to do is override the save method.

simple.
__________________
new job doesn't allow a public profile - please do not contact this user with questions, you will not get a response. good luck!
Offline  
Old 11-09-2008, 08:02 AM   #7 (permalink)
Thumbs Must Hurt
 
Join Date: Oct 2008
Model: 8800
PIN: N/A
Carrier: AT
Posts: 81
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

You don't have to implement any DialogClosed Listener ,just
override the onSavePrompt() method whose signiture is as follows,


public boolean onSavePrompt()
{
/*
synchronised(_data)
{
_data.setContents(appData)
_data.commit();
}*/
Dialog.inform("Default save appeared");
}
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.