如何添加和Gmail等Android中,以场空间标记生成器中正常删除联系人气泡multiautocompletetextview气泡、标记、器中、联系人

2023-09-05 09:38:19 作者:开着拖拉机唱情歌°

我挣扎了很多与添加的气泡到现场像Gmail或Facebook的信使。请看下面这张图..

i am struggling alot with adding the Bubbles to to field like in gmail or facebook messanger. please look into this picture below..

因此​​,对于上述画面的实现我用这个示例项目做了一些工作 他们给了code的实现,但我需要划分每个气泡空间,这意味着我已用空间分词器。那么它工作正常,但我的问题是,如果我继续增加在Gmail现场一般字段中的联系人正在起来的联系人名单列表视图显示完全。但对我来说列表视图没有显示增加最大的接触后,也如果我添加联系人的大长度的名字自动被添加多个气泡该名称。还有一问题是在2.2版本的手机,我无法看到的或接触泡沫之后的光标。手动我需要点击联系人气泡。我发现一些新闻从这链接 但我无法导入从这个完整的code https://android.googlesource.com/platform/frameworks/ex/+/refs/heads/master/chips.这么多的依赖关系在那里,所有的项目都导入。请让我知道上述问题的任何解决方案。如果任何样品也请张贴在这里。

So for the implementation of above picture i did some work using this sample project they have given code for the implementation but i need to divide the each Bubbles with space that means i used space tokenizer. then its works fine but my problem is if i am keep on adding the contacts in the to field generally in gmail to field is moving up and listview of contacts list showing completely. but in my case listview is not showing after adding the max contacts and also if i add big length of contacts name automatically it is adding multiple Bubbles for that name. and one more problem is in 2.2 version mobile i am unable to see the cursor between or after the contact Bubble. Manually i need to click on contact Bubbles . I found the some news from this link but I am unable to import the complete code from this https://android.googlesource.com/platform/frameworks/ex/+/refs/heads/master/chips. so many dependences are there and all the projects are importing. Please let me know any solution for the above problem. If any sample also please post here..

推荐答案

我开源我们的解决方案 TokenAutoComplete在github 。煤矿已经过测试,回2.2。我设计我的code允许pretty的简单实现和自定义。我不知道这是否相当回答你的问题,但它可能比芯片源$ C ​​$ C更好的起点。

I open-sourced our solution TokenAutoComplete on github. Mine has been tested back to 2.2. I designed my code to allow pretty simple implementations and customizations. I'm not sure if this quite answers your question, but it might be a better starting point than the chips source code.

下面是一个使用我的库中的一个示例实现:

Here's an example implementation using my library:

子类TokenCompleteTextView

Subclass TokenCompleteTextView

public class ContactsCompletionView extends TokenCompleteTextView {
    public ContactsCompletionView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected View getViewForObject(Object object) {
        Person p = (Person)object;

        LayoutInflater l = (LayoutInflater)getContext().getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        LinearLayout view = (LinearLayout)l.inflate(R.layout.contact_token, (ViewGroup)ContactsCompletionView.this.getParent(), false);
        ((TextView)view.findViewById(R.id.name)).setText(p.getEmail());

        return view;
    }

    @Override
    protected Object defaultObject(String completionText) {
        //Stupid simple example of guessing if we have an email or not
        int index = completionText.indexOf('@');
        if (index == -1) {
            return new Person(completionText, completionText.replace(" ", "") + "@example.com");
        } else {
            return new Person(completionText.substring(0, index), completionText);
        }
    }
}

布局$ C $下contact_token(你可以使用任何种类的布局,或在这里如果你想在令牌图像可以抛出的ImageView中)

Layout code for contact_token (you can use any kind of layout here or could throw an ImageView in if you want images in the token)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content">

    <TextView android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/token_background"
        android:padding="5dp"
        android:textColor="@android:color/white"
        android:textSize="18sp" />

</LinearLayout>

令牌backgound绘制

Token backgound drawable

<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid android:color="#ffafafaf" />
    <corners
        android:topLeftRadius="5dp"
        android:bottomLeftRadius="5dp"
        android:topRightRadius="5dp"
        android:bottomRightRadius="5dp" />
</shape>

Person对象code

Person object code

public class Person implements Serializable {
    private String name;
    private String email;

    public Person(String n, String e) { name = n; email = e; }

    public String getName() { return name; }
    public String getEmail() { return email; }

    @Override
    public String toString() { return name; }
}

样活性

public class TokenActivity extends Activity {
    ContactsCompletionView completionView;
    Person[] people;
    ArrayAdapter<Person> adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        people = new Person[]{
                new Person("Marshall Weir", "marshall@example.com"),
                new Person("Margaret Smith", "margaret@example.com"),
                new Person("Max Jordan", "max@example.com"),
                new Person("Meg Peterson", "meg@example.com"),
                new Person("Amanda Johnson", "amanda@example.com"),
                new Person("Terry Anderson", "terry@example.com")
        };

        adapter = new ArrayAdapter<Person>(this, android.R.layout.simple_list_item_1, people);

        completionView = (ContactsCompletionView)findViewById(R.id.searchView);
        completionView.setAdapter(adapter);
        completionView.setPrefix("To: ");
    }
}

布局code

Layout code

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.tokenautocomplete.ContactsCompletionView
        android:id="@+id/searchView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</RelativeLayout>