user678811
user678811

Reputation: 21

How to commit a candidate item in sample soft keyboard?

In the function pickSuggestionManually(int index) the commented documentation says the following:

// 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());

Now, how to commit one of the candidate suggestions?

Can anyone help please?

Regards, Sayantan

Upvotes: 2

Views: 742

Answers (1)

Andrew Zitnay
Andrew Zitnay

Reputation: 61

Add a function like:

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

to CandidateView.java, then replace the code you referenced with something like:

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

Upvotes: 6

Related Questions