Search in sources :

Example 11 with CompletionInfo

use of android.view.inputmethod.CompletionInfo in project little-bear-dictionary by daimajia.

the class AutoCompleteTextView method buildImeCompletions.

private void buildImeCompletions() {
    final ListAdapter adapter = mAdapter;
    if (adapter != null) {
        InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null) {
            final int count = Math.min(adapter.getCount(), 20);
            CompletionInfo[] completions = new CompletionInfo[count];
            int realCount = 0;
            for (int i = 0; i < count; i++) {
                if (adapter.isEnabled(i)) {
                    Object item = adapter.getItem(i);
                    long id = adapter.getItemId(i);
                    completions[realCount] = new CompletionInfo(id, realCount, convertSelectionToString(item));
                    realCount++;
                }
            }
            if (realCount != count) {
                CompletionInfo[] tmp = new CompletionInfo[realCount];
                System.arraycopy(completions, 0, tmp, 0, realCount);
                completions = tmp;
            }
            imm.displayCompletions(this, completions);
        }
    }
}
Also used : CompletionInfo(android.view.inputmethod.CompletionInfo) InputMethodManager(android.view.inputmethod.InputMethodManager) ListAdapter(android.widget.ListAdapter) SuppressLint(android.annotation.SuppressLint)

Aggregations

CompletionInfo (android.view.inputmethod.CompletionInfo)11 InputMethodManager (android.view.inputmethod.InputMethodManager)9 SuppressLint (android.annotation.SuppressLint)2 ListAdapter (android.widget.ListAdapter)2 Context (android.content.Context)1 Paint (android.graphics.Paint)1 Drawable (android.graphics.drawable.Drawable)1 Bundle (android.os.Bundle)1 KeyEvent (android.view.KeyEvent)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 BaseInputConnection (android.view.inputmethod.BaseInputConnection)1 CorrectionInfo (android.view.inputmethod.CorrectionInfo)1 ExtractedTextRequest (android.view.inputmethod.ExtractedTextRequest)1 AbsListView (android.widget.AbsListView)1 AdapterView (android.widget.AdapterView)1 LinearLayout (android.widget.LinearLayout)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 IOException (java.io.IOException)1