我已经为建议词做了一个数据库,
但是在哪里将它放入 android 软键盘示例以及如何在程序中使用来自 db 的词?这样我就不需要完全输入这个词,它会在数据库中显示建议词
问问题
3018 次
3 回答
1
在 SDK 中查看 Samples 文件夹,其中包含一个软键盘示例以及有关如何建议结果的更多信息。
于 2013-01-18T05:37:19.553 回答
0
要从 .db 中获取建议词,请使用SQLiteOpenHelper或SQLiteAssetsHelper。
要在候选视图中显示建议词,请修改 Google SoftKeyboard 示例项目中 SoftKeyboard.java 文件的 updateCandidates() 方法。
/**
* Update the list of available candidates from the current composing
* text. This will need to be filled in by however you are determining
* candidates.
*/
private void updateCandidates() {
if (!mCompletionOn) {
// mComposing is current text you typed.
if (mComposing.length() > 0) {
// Get suggested words list from your database here.
ArrayList<String> list = new ArrayList<String>();
list.add(mComposing.toString());
// This method will show the list as suggestion.
setSuggestions(list, true, true);
} else {
setSuggestions(null, false, false);
}
}
}
要输入从候选视图中选择的单词以输入文本,请在 SoftKeyboard 示例项目中修改以下方法。
public void pickSuggestionManually(int index) {
if (mCompletionOn && mCompletions != null && index >= 0
&& index < mCompletions.length) {
CompletionInfo ci = mCompletions[index];
getCurrentInputConnection().commitCompletion(ci);
if (mCandidateView != null) {
mCandidateView.clear();
}
updateShiftKeyState(getCurrentInputEditorInfo());
} else if (mComposing.length() > 0) {
// If we were generating candidate suggestions for the current
// text, we would commit one of them here. But for this sample,
// we will just commit the current text.
commitTyped(getCurrentInputConnection());
// You need to add getter method for suggested words shown in candidate view
}
}
于 2015-01-22T06:44:11.337 回答
0
您只需要在 SoftKeyboard.java 类中处理数据库。
于 2013-04-25T06:23:42.480 回答