问题
I have done a database for the suggestion words
but where to put it into the android soft keyboard example and how to use the words from db in the program? so that I will not need to type the word completely and it will shown the suggestion word in database
回答1:
Inside the SDK check out the Samples folder, this contains a soft keyboard example and more information on how to suggest results.
回答2:
You just need to handle database in SoftKeyboard.java Class.
回答3:
To get the suggestion words from .db, please use SQLiteOpenHelper or SQLiteAssetsHelper.
To show the suggestion words in candidate view, please modify the updateCandidates() method of SoftKeyboard.java file in Google SoftKeyboard example project.
/**
* 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);
}
}
}
To enter the picked word from candidate view to input text, please modify following method in SoftKeyboard example project.
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
}
}
来源:https://stackoverflow.com/questions/14392873/how-to-develop-android-soft-keyboard-example-with-a-database