How to prevent dialog from closing automatically on click in blackberry - blackberry

I am developing an application in which i create a Dialog with Edit Field and save/Cancel button, i use validation on edit field,i want that if user enter valid entry and click save then the dialog should close but now the problem is when user click on save without enter any text in edit field dialog closes automatically,i want to prevent it after entering valid entry dialog should close.
I give cancel button to discard dialog.
Please help..how to achieve this..........

mOKButton.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field f, int arg1) {
if(_editText.getText()=="")
{
// do nothing
}
else{
_editText.setText(items[getSelectedIndex()]);
close();
}
}
});

Related

Can i call dialog box on popup screen in blackberry?

In my blackberry application i make one popup screen which is popup on click of menu item. on that popup screen i took one button. Now i want to show alert dialog box on click of that button.How to do this ?Plz tell me.
You can do like this.
public void fieldChanged(Field field, int context)
{
if(field.equals(your button object))
{
Dialog.alert("Your message");
}
}

Add field manager to application Main screen in BlackBerry

I am working with a BlackBerry application for OS 5.0 and later. The application has one screen which displays at the top of screen a Next and a Previous button. and list field also display in this screen at bottom of these both button
When i click on NEXT Button and Previous Button my List will be updated display data..
When i click on NEXT/PREVIOUS Button i have to display small VerticalfieldManager at the center of the screen with Label "Please wait ..." so after design this screen how can we add more field manager in over the another manager ?
Is there any way to display that Field at the application MainScreen like iPhone AppDelegate screen?
btnState.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context)
{ vfm_Middle.add(lblPleasewait);
popup = new PopupScreen(manager);
Thread thread = new Thread()
{
public void run()
{
try
{
Updatelistfield();
stop();
}
catch (InterruptedException e)
{
e.printStackTrace();
}
super.run();
}
public synchronized void stop()
{
// TODO Auto-generated method stub
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run()
{
// TODO Auto-generated method stub
//popup.delete(vfm_Main);
//popup.deleteAll();
//vfm_Main.delete(lblPleasewait);
//lblPleasewait.setText(null);
}
});
}
};
thread.start();
}
});
The proper way of doing that is with a blocking dialog. In BB API this can be done as follows:
VerticalFieldManager manager = new VerticalFieldManager();
manager.add(new LabelField("Please Wait..."));
Screen popup = new PopupScreen(manager);
//Show the pop-up the same way you push a regular screen
This has the advantage of blocking the GUI: if the user pushes the menu or esc key it doesn't have any effect.
If you want to do it in your screen without dialogs, then you can add an empty VerticalFieldManager which you can fill with a label when the message has to be shown. This way, instead of updating the entire screen, only the Manager is refreshed. But then you should write the logic to not letting the user push any button or menu key (or ignoring key press).

Blackberry popup menu appear on Button click event

I have a problem that popup menu appear when I click a button field. I will solve it by using Buttonfield.consumeclick but it also appears on RichTextField focus. How can I solve this? I am overriding RichTextField method, and that is the reason the popup menu appears.
ButtonField c = new ButtonField("button", FIELD_LEFT | ButtonField.CONSUME_CLICK) {
protected boolean navigationClick(int status, int time) {
Status.show("Button has clicked");
// write your code.
return true;
}
}

text field in a dialog box on a BlackBerry

I want to create an empty dialog box with a text field inside. When the user enters data inside the box he must be redirected to another screen. I want the Dialog box to come up without any statements but must include a textfield
That should be doable with a PopupScreen, EditField and maybe a ButtonField so the user can let you know he/she is done entering data.
Just create standard OK dialog and then add an EditField to it.
BasicEditField inputField = new BasicEditField();
Dialog d = new Dialog(Dialog.D_OK_CANCEL, "Enter your Username:", Dialog.OK, null, Dialog.DEFAULT_CLOSE);
d.add(inputField);
int i = d.doModal();
if (i == Dialog.OK) {
Dialog.inform("Your Username is : " + inputField.getText());
}
Here's a complete tutorial

How could i avoid the SAVE dialog in my custom blackberry Application?

I am writing a blackberry application and pushing screens one after another(three in series)
Screen1 displays Screen2 and Screen2 displays Screen3
When i press "Back Key" on my Blackberry Device i.e., bold 9700, its prompts a dialog box with Question mark image and buttons "Save" "Discard" "Cancel".
Why does this dialog appears?
How can i avoid this dialog?
Please Help
Thanks
SIA
you can avoid this type of dialog by overriding onClose method for that screen :
public boolean onClose()
{
this.close();
return true;
}
There are two ways of doing this:
Override the isDirty() method of your Screen (via: Blackberry - Disable Save option in BasicEditField?):
public boolean isDirty() { return false; }
You can also override the onSavePrompt() method of your Screen (also via: Blackberry - Disable Save option in BasicEditField?):
protected boolean onSavePrompt() { return true; }
Simply Write this code in your specified class:
protected boolean onSavePrompt()
{
return true;
}
It will disable the Save Prompt Dialog Box.

Resources