如何在样本软键盘中提交候选项?

use*_*811 1 android android-softkeyboard

在该函数中pickSuggestionManually(int index) ,注释文档说明如下:

// 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());
Run Code Online (Sandbox Code Playgroud)

现在,如何提交一个候选建议?

有人可以帮忙吗?

问候,Sayantan

小智 5

添加如下功能:

public String getSuggestion(int index)
{
    return index >= 0 && mSuggestions != null && index < mSuggestions.size() ? mSuggestions.get(index) : "";
}
Run Code Online (Sandbox Code Playgroud)

到CandidateView.java,然后将你引用的代码替换为:

        if (mCandidateView != null) {
            getCurrentInputConnection().commitText(
                    mCandidateView.getSuggestion(index),
                    mCandidateView.getSuggestion(index).length());
            mComposing.setLength(0);
            updateCandidates();
        }
Run Code Online (Sandbox Code Playgroud)