Code example for AutoCompleteTextView

Methods: getTextsetSelectiongetSelectionStart, clearComposingText, requestFocus, showDropDown

0
            Toast.makeText(mContext, R.string.prompt_mention_typing_start, Toast.LENGTH_SHORT).show();
        } 
 
        public void onClick(View arg0) {
            if (null != mEditText) {
                mEditText.clearComposingText();
                int index = mEditText.getSelectionStart();
                Editable editable = mEditText.getText();
 
                if (index < 0) {
                    editable.append("+");
                } else if (index >= editable.length()) {
                    if (0 == index) {
                        editable.append("+");
                    } else if (isMentionTrigger(editable.charAt(index - 1))) {
                        showPrompt(); 
                    } else { 
                        editable.append(" +");
                    } 
                } else { 
                    final char preChar = index > 0 ? editable.charAt(index - 1) : ' ';
                    final char curChar = editable.charAt(index);
                    if (Character.isSpaceChar(preChar)) {
                        if (Character.isSpaceChar(curChar)) {
                            editable.insert(index, "+");
                        } else { 
                            if (isMentionTrigger(curChar)) {
                                showPrompt(); 
                            } else { 
                                editable.insert(index, "+ ");
                                mEditText.setSelection(index + 1);
                            } 
                        } 
                        // TODO : reform this code and consider bellowing cases. 
//                    } else if (isMentionTrigger(preChar)) { 
//                        if (Character.isSpaceChar(curChar)) { 
//                            editable.insert(index, " +"); 
//                        } else { 
//                            editable.insert(index, " + "); 
//                            mEditText.setSelection(index + 2); 
//                        } 
                    } else { 
                        if (Character.isSpaceChar(curChar)) {
                            editable.insert(index, " +");
                        } else { 
                            editable.insert(index, " + ");
                            mEditText.setSelection(index + 2);
                        } 
                    } 
                } 
                mEditText.requestFocus();
//                InputMethodManager imm = (InputMethodManager)mEditText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); 
//                imm.showSoftInput(mEditText, 0); 
//                imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0); 
                mEditText.showDropDown();
            } 
        } 
    } 
}