自AutoCompletevView像Android的Facebook的留言栏 [英] Custom AutoCompletevView like facebook comments field in android

查看:164
本文介绍了自AutoCompletevView像Android的Facebook的留言栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想进行自定义AutoCompleteView这样的..

I want to make custom AutoCompleteView like this..

应该当我的特殊字符添加(如Facebook。当你键入@B那​​么所有这些朋友名字以B将填充开始,我们可以选择名称)进行填充。

It should be populated when my special character is added (like facebook.. When you type @B then all friends those name starts with 'B' will be populated and we can select name).

同时打字,直到它不应该被填充'@'被添加。

It should not be populate while typing until '@' is added.

在'@'添加autocompleteview掉落下来,我们可以选择名称并选择后,将被追加。

When '@' is added autocompleteview is dropped down and we can select name and after selecting it will be appended.

我发现这个,但并不满足。我需要的线索。他们已经实现了......就像当你键入@下拉populates.But我要自定义更多。现在,我需要帮助,如果其他是有想法或任何完成的来源。

I found this but not satisfied. I need clue. They have implemented...like when you type '@' dropdown populates.But I have to customize more. Right now I need help if other is having idea or any in-completed source.

我要尝试自己,但让我实现customview节省我的时间之前问了。

I have to try myself but let me ask before implementing customview to save my time.

推荐答案

您必须使自定义通过扩展在你的问题中提到的类..和code被改变autocompleteview。

You have to make custom autocompleteview by extending class.. and code mentioned in your question to be changed.

public class CustomAutoComplete extends AutoCompleteTextView {
private String previous = "";
private String seperator = "@";
boolean isState = false;

public CustomAutoComplete(final Context context, final AttributeSet attrs,
        final int defStyle) {
    super(context, attrs, defStyle);
    this.setThreshold(1);

}

public CustomAutoComplete(final Context context, final AttributeSet attrs) {
    super(context, attrs);
    this.setThreshold(1);
}

public CustomAutoComplete(final Context context) {
    super(context);
    this.setThreshold(1);
}

/**
 * This method filters out the existing text till the separator and launched
 * the filtering process again
 */
@Override
protected void performFiltering(final CharSequence text, final int keyCode) {
    String filterText = text.toString().trim();
    String lastchar = filterText.substring(filterText.length() - 1,
            filterText.length());
    if (filterText.length() == 1) {
        if (lastchar.equals(seperator)) {
            isState = true;
        } else {
            isState = false;
        }
    }
    previous = filterText.substring(0,
            filterText.lastIndexOf(getSeperator()) + 1);

    filterText = filterText.substring(filterText
            .lastIndexOf(getSeperator()) + 1);

    if ((lastchar.equals(seperator)) || isState) {
        super.performFiltering(filterText, keyCode);

        isState = true;

    }
}

/**
 * After a selection, capture the new value and append to the existing text
 */
@Override
protected void replaceText(final CharSequence text) {
    isState = false;
    super.replaceText(previous + text);// + getSeperator());

}

public String getSeperator() {
    return seperator;
}

public void setSeperator(final String seperator) {
    this.seperator = seperator;
}

}

希望这会帮助你...

Hope this will help you...

这篇关于自AutoCompletevView像Android的Facebook的留言栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆