Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Highlighted
Developer
Posts: 80
Registered: ‎09-03-2012
My Device: 9810
My Carrier: Vodafone
Accepted Solution

Dialog's button field access in a BlackBerry 7 app

How to access dialog's button field (Ok , Cancel etc) if we create a dialog as follows :

 

 

public static void showDialog(String iMsg) {

		Dialog dialog = new Dialog(Dialog.D_OK_CANCEL, iMsg, Dialog.CANCEL,
				null, 0);
		dialog.setChangeListener(new FieldChangeListener() {

			public void fieldChanged(Field field, int context) {

				if (field.getState() == Dialog.OK) {
					Status.show("Ok Clicked", 1000);
				} else if (field.getState() == Dialog.CANCEL) {
					Status.show("Cancel Clicked", 1000);
				} else {
					Status.show("None Clicked", 1000);
				}

			}
		});
		dialog.show();

	}

 I am trying to access it like this but not been successful yet .


I got another successful way to put actions on dialog's Button field actions is :


public static void showDialog(String iMsg) {

		int response = Dialog.ask(Dialog.D_OK_CANCEL, iMsg);
		if (response == Dialog.OK) {
			Status.show("Ok Clicked", 1000);
		} else if (response == Dialog.CANCEL) {
			Status.show("Cancel Clicked", 1000);
		} else {
			Status.show("None Clicked", 1000);
		}

	}

 

 

 

But I want to know if its possible to show define action to dialog's button field's if we are following the first way to create Dialog.

 

 

 

 

Always Success
Developer
Posts: 80
Registered: ‎09-03-2012
My Device: 9810
My Carrier: Vodafone

Re: Dialog's button field access in a BlackBerry 7 app

Problem Resolved :

 

Correct Listener to be registered  will be DialogClosedListener. and hence correct code will be

 

public static void showDialog(String iMsg) {

		Dialog dialog = new Dialog(Dialog.D_OK_CANCEL, iMsg, Dialog.CANCEL,
				null, 0);
		
		dialog.setDialogClosedListener(new DialogClosedListener() {

			public void dialogClosed(Dialog dialog, int choice) {

				if (choice == Dialog.OK) {
					System.out
							.println("********************************************   OK");
					Status.show("Ok Clicked", 1000);
				} else if (choice == Dialog.CANCEL) {
					System.out
							.println("********************************************   Cancel");
					Status.show("Cancel Clicked", 1000);
				} else {
					System.out
							.println("********************************************   None");
					Status.show("None Clicked", 1000);
				}

			}
		});

		dialog.show();

 

Always Success