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: 33
Registered: ‎12-03-2011
My Device: 9800
My Carrier: Blackberry

on back save prompt not shown

i have not seen save prompt after edit a field when press back button

 

code here:

final class HelloWorldScreen extends MainScreen implements FieldChangeListener
{



HelloWorldScreen()
{


// Set the displayed title of the screen
setTitle("hello");



BasicEditField Name1EditField = new BasicEditField(
"",
preference.getMyName()[0],
105,
EditField.FILTER_UPPERCASE);
Name1EditField.setChangeListener(new FieldChangeListener(){
public void fieldChanged(Field field, int context)
{
String text = ((BasicEditField)field).getText();

}
});
vfm.add(msg1EditField);
private static void savePreference()
{
synchronized( persist )
{
persist.commit();
}
}


private void run() {
// TODO Auto-generated method stub

}


/**
* Displays a dialog box to the user with the text "Goodbye!" when the
* application is closed.
*
* @see net.rim.device.api.ui.Screen#close()
*/
public void close()
{
// Display a farewell message before closing the application
//Dialog.alert("Goodbye!");
super.close();
}

public boolean onSavePrompt(){
savePreference();
return true;
}


/**
* FieldChangeListener implementation. Displays a popup informing the user
* of what button was clicked.
* @see net.rim.device.api.ui.FieldChangeListener#fieldChanged(Field, int)
*/
form(text + " was clicked.");
}

}

 

Developer
Posts: 208
Registered: ‎08-04-2009
My Device: Not Specified

Re: on back save prompt not shown

It seems Save dialog is not invoking, since onSavePrompt is overrided by you.

Please test by following steps:

public boolean onSavePrompt(){
savePreference();
return super.onSavePrompt();
}

Contributor
Posts: 33
Registered: ‎12-03-2011
My Device: 9800
My Carrier: Blackberry

Re: on back save prompt not shown

Thanks sir..its working now show prompt for save discard cancel....

but still i have some problem

when i edit text and press back button it show prompt for save...suppose i delete some text and press back and then press discard it still delete the text..after discard

what is the actual work of discard let me know

 

Highlighted
Developer
Posts: 208
Registered: ‎08-04-2009
My Device: Not Specified

Re: on back save prompt not shown

onSavePrompt is method of MainScreen is invoked on pressing of back key on the screen, and according to your current implementation, it will call savePreference method irrespective of your choice in Save Prompt Dialog, if you want to call this method only on selection of Save Button, don't override onSavePrompt method, instead override onSave() method and write your code there in onSave method.

Contributor
Posts: 33
Registered: ‎12-03-2011
My Device: 9800
My Carrier: Blackberry

Re: on back save prompt not shown

thanks sir it work fine..how how to override discard button..it also save my change.in actuall it will discard my changes.

Developer
Posts: 208
Registered: ‎08-04-2009
My Device: Not Specified

Re: on back save prompt not shown

Discard Button Does noting, so you dont need to override anything if you want nothing to save on discard button, but if you want to perform some functionality on discard button you would need to create your custom onSavePrompt dialog and override onSavePrompt Dialog and would need to display your dialog instead of the original one.

Contributor
Posts: 33
Registered: ‎12-03-2011
My Device: 9800
My Carrier: Blackberry

Re: on back save prompt not shown

but my discard button save the change which i have done.discard work same as SAVE.

Developer
Posts: 208
Registered: ‎08-04-2009
My Device: Not Specified

Re: on back save prompt not shown

Remove method:

 

public boolean onSavePrompt(){
savePreference();
return super.onSavePrompt();
}

 

from the class.

and keep following method

 

public void onSave(){
savePreference();

}

Contributor
Posts: 33
Registered: ‎12-03-2011
My Device: 9800
My Carrier: Blackberry

Re: on back save prompt not shown

Still save on discard click...

Developer
Posts: 208
Registered: ‎08-04-2009
My Device: Not Specified

Re: on back save prompt not shown

Paste your code here, so I can look into the code, and you also set a breakipoint on onSave method,and check if onSave method is being invoked even on discard button.