我为建议词语做了一个数据库 但是在哪里把它放到android软键盘示例中以及如何在程序中使用db中的单词?所以我不需要完全输入这个词,它会在数据库中显示建议词
答案 0 :(得分:1)
在SDK内部查看Samples文件夹,其中包含软键盘示例以及有关如何建议结果的更多信息。
答案 1 :(得分:0)
您只需要在SoftKeyboard.java类中处理数据库。
答案 2 :(得分: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
}
}