我让它与自定义'@'标记器一起使用。但它在第一次自动完成时失败了。我的代码作为逗号标记器工作,我只在逗号之后获得任何字符的建议和下一个建议(在我的情况下是'@')。这是我的代码。
String[] str={"Andoid","Jelly Bean","Froyo",
"Ginger Bread","Eclipse Indigo","Eclipse Juno"};
editEmojicon.setTokenizer(new MultiAutoCompleteTextView.Tokenizer() {
@Override
public int findTokenStart(CharSequence text, int cursor) {
int i = cursor;
while (i > 0 && text.charAt(i - 1) != '@') {
i--;
}
while (i < cursor && text.charAt(i) == ' ') {
i++;
}
return i;
}
@Override
public int findTokenEnd(CharSequence text, int cursor) {
int i = cursor;
int len = text.length();
while (i < len) {
if (text.charAt(i) == ' ') {
return i;
} else {
i++;
}
}
return len;
}
@Override
public CharSequence terminateToken(CharSequence text) {
int i = text.length();
while (i > 0 && text.charAt(i - 1) == ' ') {
i--;
}
if (i > 0 && text.charAt(i - 1) == ' ') {
return text;
} else {
if (text instanceof Spanned) {
SpannableString sp = new SpannableString(text + " ");
TextUtils.copySpansFrom((Spanned) text, 0, text.length(),
Object.class, sp, 0);
return sp;
} else {
return text+" ";
}
}
}
});
ArrayAdapter<String> adp=new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line,str);
editEmojicon.setThreshold(1);
editEmojicon.setAdapter(adp);
在这里看到了这篇文章但是没有用。如果有人可以帮助我,我将不胜感激。
EmojiconEditText.java
public class EmojiconEditText extends MultiAutoCompleteTextView {
private int mEmojiconSize;
public EmojiconEditText(Context context) {
super(context);
mEmojiconSize = (int) getTextSize();
}
public EmojiconEditText(Context context, AttributeSet attrs) {
super(context, attrs);
init(attrs);
}
public EmojiconEditText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(attrs);
}
private void init(AttributeSet attrs) {
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.Emojicon);
mEmojiconSize = (int) a.getDimension(R.styleable.Emojicon_emojiconSize, getTextSize());
a.recycle();
setText(getText());
}
@Override
protected void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) {
EmojiconHandler.addEmojis(getContext(), getText(), mEmojiconSize);
}
/**
* Set the size of emojicon in pixels.
*/
public void setEmojiconSize(int pixels) {
mEmojiconSize = pixels;
}
/** For Mention System / Added by midhun **/
@Override
protected void performFiltering(CharSequence text, int start, int end, int keyCode) {
if (text.charAt(start) == '@') {
start = start + 1;
} else {
text = text.subSequence(0, start);
for (int i = start; i < end; i++) {
text = text + "*";
}
}
super.performFiltering(text, start, end, keyCode);
}
}