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));
Previous topic: Spelling checker

Was this information helpful? Send us your comments.