Spelling Checker
Spelling Checker:拼字檢查。
為何使用Spelling Checker,需要用SpellCheckerSessionListener 介面覆蓋方法。
例如:
public class HelloSpellCheckerActivity extends Activity implements SpellCheckerSessionListener {
public void onGetSuggestions(final SuggestionsInfo[] arg0) {
// TODO Auto-generated method stub
}
public void onGetSentenceSuggestions(SentenceSuggestionsInfo[] arg0) {
// TODO Auto-generated method stub
}
}
接下來的事,需要建立SpellCheckerSession 類別,還需要呼叫TextServicesManager裡面的newSpellCheckerSession方法。
例如:
private SpellCheckerSession mSc;
final TextServicesManager tsm = (TextServicesManager) getSystemService(
Context.TEXT_SERVICES_MANAGER_SERVICE);
mSc = tsm.newSpellCheckerSession(null, null, this, true);
//Context.TEXT_SERVICES_MANAGER_SERVICE:
最後一件,還需要呼叫getSuggestions方法來取得建議的任何文字。之後建議會送到onGetSuggestions 方法裡面。
例如:
mSc.getSuggestions(new TextInfo(editText1.getText().toString()), 3);
第一個參數是文字信息對象的形式的字符串。
第二個參數是用來區分建議cookie的數量。
SpellCheckerSession 其他類別
cancel():取消待定或是執行中拼字檢查任務。
close():關閉拼字檢查。
getSentenceSuggestions(TextInfo[] textInfos, int suggestionsLimit):從指定的句子取得建議。
getSpellChecker():
isSessionDisconnected():判斷文字檢查是否斷線。
參考文獻
Android - Spelling Checker
Android拼寫檢查教程
SpellCheckerSession
沒有留言:
張貼留言