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
Contributor
Posts: 12
Registered: ‎02-24-2011
My Device: Curve 8520
My Carrier: Vodafone, India

Custom Dialog box button pressed.

I'm creating Login Dialog box which runs at the device start up. Dialog Box displayed nicely. But how to know that which button pressed by user is it "Login" or "Cancel". is there any method? I passed button to dialog box. my code is as follow.

 

 

import java.util.Vector;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.PersistentObject;
import net.rim.device.api.system.PersistentStore;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.component.PasswordEditField;
import net.rim.device.api.util.Persistable;

public final class logindialog extends Dialog implements FieldChangeListener {

	// TODO Auto-generated constructor stub}
	private EditField login_id;
	private PasswordEditField password;
	private ButtonField info;

	private static PersistentObject store_value;
	private static Vector data;
	private static String choices[]={"Login","Cancel"};
	private static int values[] ={Dialog.OK,Dialog.CANCEL};

	public logindialog() {

		super("Login", choices,values,Dialog.OK, Bitmap.getPredefinedBitmap(Bitmap.INFORMATION), Dialog.GLOBAL_STATUS);

		login_id = new EditField("UserID:", "");
		password = new PasswordEditField("Password:", "");
		info = new ButtonField("Help?", ButtonField.CONSUME_CLICK);
		info.setChangeListener(this);
		
		add(login_id);
		add(password);
	}

	public void fieldChanged(Field field, int context) {
		if (field == info) {
			Dialog.alert("information");
		}
	}

	static {
		store_value = PersistentStore.getPersistentObject(0xdec6a67f7444cL);
		synchronized (store_value) {
			if (store_value.getContents() == null) {
				store_value.setContents(new Vector());
				store_value.commit();
			}
		}
		data = new Vector();
		data = (Vector) store_value.getContents();
	}

	private static final class Store implements Persistable {
		/* Vector to store data */
		private Vector elements;

		public static final int u_id = 0;
		public static final int pass = 1;

		public Store() {
			elements = new Vector(2);
			for (int i = 0; i < elements.capacity(); i++) {
				elements.addElement(new String(""));
			}
		}

		public String getElement(int id) {
			return (String) elements.elementAt(id);
		}

		public void setElement(int id, String value) {
			elements.setElementAt(value, id);
		}
	}
}

 

 

Developer
Posts: 588
Registered: ‎05-29-2009
My Device: 9100

Re: Custom Dialog box button pressed.

You can check it out with getSelectedValue().

 

Contributor
Posts: 12
Registered: ‎02-24-2011
My Device: Curve 8520
My Carrier: Vodafone, India

Re: Custom Dialog box button pressed.

i'm new in developing application so will u plz give information where to use it??

Developer
Posts: 588
Registered: ‎05-29-2009
My Device: 9100

Re: Custom Dialog box button pressed.

Try something like this from you want to invoke this dialog....

 

 

loginDialog d = new loginDialog(....);
d.doModal();
int result = d.getSelectedValue();

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Custom Dialog box button pressed.

Welcome to the forums and Blackberry development.

 

The following is just my personal opinion, use it as you will.....

 

Have to say for me your code looks, well, unusual.  A Dialog is a UI element.  In this case your UI Element also knows about some data storage.  That doesn't sound like good practice to me  I would think carefully about what each of the Objects in your application is actually doing and what their purpose is and try to keep data, logic and UI as far apart as possible. 

 

So a more usual case for a Dialog would go:

A class that implements the Business Logic, obtains some data from a Data class, and then decides it needs to ask the user a question.  So it creates a Dialog (UI Class) with the question and waits for a response.

 

In that scenario, then the Business Logic would create a Dialog, and then get it's selected value using the method the previous poster told you about.  That is how it is meant to be used. 

 

In summary, I would rethink your application design.  But that is just me. 

 

Hope this helps. 

Contributor
Posts: 12
Registered: ‎02-24-2011
My Device: Curve 8520
My Carrier: Vodafone, India

Re: Custom Dialog box button pressed.

Actually i'm creating security software that provice password protection and i'm reading value from memory. So on login dialog box i have to use the memory read operation.