Would you like to tell us how we are doing?

You bet No thanks

Sorry about the red box, but we really need you to update your browser. Read this excellent article if you're wondering why we are no longer supporting this browser version. Go to Browse Happy for browser suggestions and how to update.

Spelling checker

You can use the items in the net.rim.blackberry.api.spellcheck package to add spelling checker functionality to an application. The SpellCheckEngine interface enables an application to check the spelling of a UI field value and provide a BlackBerry device user with options for spelling corrections. The SpellCheckUI interface enables an application to provide a UI that allows a BlackBerry device user to resolve a spelling issue- by interacting with the SpellCheckEngine implementation.

For more information about using the Spell Check API, see the Spell Check sample application, which is provided with BlackBerry Java Development Environment 4.3.1 or later, and with the BlackBerry Java Plug-in for Eclipse.

Add spell check functionality

  1. Import the following classes:

    • net.rim.blackberry.api.spellcheck.SpellCheckEngineFactory
    • java.lang.StringBuffer
  2. Import the following interfaces:

    • net.rim.blackberry.api.spellcheck.SpellCheckEngine
    • net.rim.blackberry.api.spellcheck.SpellCheckUI
    • net.rim.blackberry.api.spellcheck.SpellCheckUIListener
  3. Create variables for spell check objects.

    SpellCheckEngine _spellCheckEngine;
    SpellCheckUI _spellCheckUI;
  4. Invoke createSpellCheckUI().

    _spellCheckUI = SpellCheckEngineFactory.createSpellCheckUI();
  5. To notifiy an application when a spell check event occurs, invoke addSpellCheckUIListener() with a SpellCheckUIListener object as a parameter.

    _spellCheckUI.addSpellCheckUIListener(new SpellCheckUIListener());
  6. To let an application spell check UI fields and suggest spelling corrections to a BlackBerry device user, obtain a SpellCheckEngine object, invoke getSpellCheckEngine().

    _spellCheckEngine = _spellCheckUI.getSpellCheckEngine();
  7. To use a correction for a misspelled word, invoke SpellCheckEngine.learnCorrection(). Use the parameters new StringBuffer(text), new StringBuffer(correction), where text represents the misspelled word, and correction represents the correct word.

    _spellCheckEngine.learnCorrection(new StringBuffer(text), 
          new StringBuffer(correction));
  8. To perform spell check operations on a field, invoke SpellCheckUI.spellCheck(), with a field as a parameter.

  9. To accept a misspelled word as correctly spelled, invoke SpellCheckEngine.learnWord(), with the word to learn as a parameter.

    _spellCheckEngine.learnWord(new StringBuffer(word));

Listen for a spell check event

  1. Import the following classes:

    • java.lang.StringBuffer
    • net.rim.device.api.ui.UiApplication
    • net.rim.device.api.ui.Field
  2. Import the following interfaces:

    • net.rim.blackberry.api.spellcheck.SpellCheckUIListener
    • net.rim.blackberry.api.spellcheck.SpellCheckEngine
  3. Create a method that returns the SpellCheckUIListener.LEARNING_ACCEPT constant when the SpellCheckEngine learns a new word.

    public int wordLearned(SpellCheckUI ui, StringBuffer word) {
       UiApplication.getUiApplication().invokeLater(new popUpRunner("Word learned")); 
       return SpellCheckUIListener.LEARNING_ACCEPT;
  4. Create a method that returns the SpellCheckUIListener.LEARNING_ACCEPT constant when the SpellCheckEngine learns a correction for a word.

    public int wordCorrectionLearned(
           SpellCheckUI ui, StringBuffer word, StringBuffer correction){ 
       UiApplication.getUiApplication().invokeLater(new popUpRunner("Correction learned"));         
       return SpellCheckUIListener.LEARNING_ACCEPT;
  5. Create a method that returns the SpellCheckUIListener.ACTION_OPEN_UI constant when the SpellCheckEngine finds a misspelled word.

    public int misspelledWordFound(
           SpellCheckUI ui, Field field, int offset, int len){
       UiApplication.getUiApplication().invokeLater(new popUpRunner(
           "Misspelled word found")); 
       return SpellCheckUIListener.ACTION_OPEN_UI;