简体   繁体   English

如何将联系人光标数据绑定到带有芯片的MultiAutoCompleteTextView

[英]How do I bind contact cursor data to a MultiAutoCompleteTextView with chips

I have been at this for almost two weeks now. 我到这已经快两个星期了。 I believe I have come close, but I can't quite get the final product to work. 我相信我已经接近了,但是我无法完全使最终产品正常工作。 I have a functionality similar to email in my app. 我的应用程序具有类似于电子邮件的功能。 But instead of email addresses, it uses phone numbers. 但是,它使用电话号码代替电子邮件地址。 The gmail app on android is able to use a MultiAutoCompleteTextView with chips to display recipient email addresses. Android上的gmail应用程序可以使用带有芯片的MultiAutoCompleteTextView来显示收件人的电子邮件地址。 That is what I want to do. 那就是我想做的。 Through my research and trials, I am able to create the MultiAutoCompleteTextView, but without the chips. 通过我的研究和试验,我能够创建MultiAutoCompleteTextView,但是没有芯片。 There are a number of questions and answers here on the same subject. 在同一主题上有许多问题和答案。 But invariably, none of the ones I find has an example that binds the data from a user's contact book to the MultiAutoCompleteTextView. 但总是可以找到一个示例,该示例没有将用户通讯录中的数据绑定到MultiAutoCompleteTextView的示例。 All the examples I see use their own made up simple arrays, as if the final step were trivial. 我看到的所有示例都使用它们自己组成的简单数组,好像最后一步是微不足道的。 But the final step is where I am stuck. 但是最后一步是我陷入困境。 Each time I try to bind the contact book to an MultiAutoCompleteTextView with chips, the code fails. 每次我尝试将通讯录绑定到带有芯片的MultiAutoCompleteTextView时,代码都会失败。 So my question is quite extremely specific: How do I bind the contact book to an MultiAutoCompleteTextView with chips? 所以我的问题非常具体: 如何将通讯录绑定到带有芯片的MultiAutoCompleteTextView? For some context, I have already read Chips widget in Android application and bunch of other articles and responses besides. 在某些情况下,我已经阅读了Android应用程序中的Chips小部件 ,此外还阅读了其他文章和响应。 Is anyone aware of my specific use case? 有人知道我的特定用例吗? The gmail use case? Gmail用例?

EDIT 编辑

Following is the code I use with https://github.com/splitwise/TokenAutoComplete . 以下是我在https://github.com/splitwise/TokenAutoComplete中使用的代码。 But the getView of my adapter is never called. 但是我的适配器的getView从未被调用。

code to bind adapter to editText 将适配器绑定到editText的代码

mAdapter = new ContactAdapter(getActivity(), mPeopleList, R.layout.contacts_row);
multiEdit = (ContactsAutoCompleteView) view.findViewById(R.id.multi_edit);
multiEdit.setAdapter(mAdapter);

code to load contact book 加载通讯录的代码

public void PopulatePeopleList() {

    mPeopleList.clear();

    Cursor people = getActivity().getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null,
            null);

    while (people.moveToNext()) {
        String contactName = people.getString(people.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));

        String contactId = people.getString(people.getColumnIndex(ContactsContract.Contacts._ID));
        String hasPhone = people.getString(people.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));

        if (Integer.parseInt(hasPhone) > 0) {

            // You know have the number so now query it like this
            Cursor phones = getActivity().getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                    null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + contactId, null, null);
            while (phones.moveToNext()) {

                // store numbers and display a dialog letting the user select which.
                String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                String numberType = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE));

                if (numberType.equals("0")) {
                    numberType = "Work";
                } else if (numberType.equals("1")) {
                    numberType = "Home";
                } else if (numberType.equals("2")) {
                    numberType = "Mobile";
                } else {
                    numberType = "Other";
                }
                mPeopleList.add(new Contact(contactName, phoneNumber, numberType));
            }
            phones.close();
        }
    }
    people.close();

    getActivity().startManagingCursor(people);
}

my adapter 我的适配器

public class ContactAdapter extends ArrayAdapter<Contact> {

    private final Context mContext;
    private final int mRowResourceId;
    private final LayoutInflater mInflater;
    ArrayList<Contact> mContacts;

    public ContactAdapter(Context context, ArrayList<Contact> contacts, int contactsRow) {
        super(context, contactsRow, contacts);
        mContext = context;
        mRowResourceId = contactsRow;
        mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mContacts = contacts;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View rowView = convertView;
        if (null == rowView) {
            rowView = mInflater.inflate(mRowResourceId, parent, false);
            ViewHolder viewsHolder = new ViewHolder();
            viewsHolder.name = (TextView) rowView.findViewById(R.id.contact_name);
            viewsHolder.phone = (TextView) rowView.findViewById(R.id.contact_phone);
            viewsHolder.type = (TextView) rowView.findViewById(R.id.contact_type);
            rowView.setTag(viewsHolder);
        }
        ViewHolder viewsHolder = (ViewHolder) rowView.getTag();
        Contact con = mContacts.get(position);// getItem(position);
        viewsHolder.name.setText(con.getName());
        viewsHolder.phone.setText(con.getPhone());
        viewsHolder.type.setText(con.getType());
        return rowView;
    }

    static class ViewHolder {
        TextView name;
        TextView phone;
        TextView type;
    }

}

my contact object: accessors and constructor not shown 我的联系对象:访问器和构造函数未显示

public class Contact implements Serializable {
    private static final long serialVersionUID = 1L;
    private String name;
    private String phone;
    private String type;
}

My TokenCompleteTextView: ?? 我的TokenCompleteTextView:?? what goes inside defaultObject defaultObject里面有什么

public class ContactsAutoCompleteView extends TokenCompleteTextView {

public ContactsAutoCompleteView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

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

    LayoutInflater l = (LayoutInflater) getContext().getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    RelativeLayout view = (RelativeLayout) l.inflate(R.layout.contacts_row,
            (ViewGroup) ContactsAutoCompleteView.this.getParent(), false);
    ((TextView) view.findViewById(R.id.contact_name)).setText(p.getName());
    ((TextView) view.findViewById(R.id.contact_phone)).setText(p.getPhone());
    ((TextView) view.findViewById(R.id.contact_type)).setText(p.getType());

    return view;
}

@Override
protected Object defaultObject(String completionText) {
    //what goes here?
}

@Override
public void setSelected(boolean selected) {
    super.setSelected(selected);

}

} }

Few weeks ago i was in your situation, and what I did was to use a library for the chips 几周前,我处于您的境地,而我所做的就是使用一个库来存放芯片

I used this one 我用这个

as for the bind with the contacts be more specific where are you stuck and what are you get ? 至于与联系人的绑定更具体地说明您困在哪里,得到什么?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何获得类似于Facebook应用程序的MultiAutoCompleteTextView标记器? - How do I get MultiAutoCompleteTextView tokenizer similar to Facebook app? 使用SpannableStringBuilder添加图像跨度后,如何防止光标在EditText(MultiAutoCompleteTextView)中调整大小? - How can I prevent the cursor from resizing in an EditText (MultiAutoCompleteTextView) after I add an imagespan using a SpannableStringBuilder? Android MultiAutoCompleteTextView自定义数据 - Android MultiAutoCompleteTextView Custom Data 如何在multiautocompletetextview中正确添加和删除Contact Bubbles,并将空间标记器(如gmail)添加到android中的字段 - How Add and delete the Contact Bubbles properly in multiautocompletetextview with space tokenizer like gmail to field in android 单击联系人条目数据(例如生日)时如何绑定我的活动? - How to bind my activity when a contact entry data, such as birthday is clicked? 如何在TokenAutoComplete中的android中的multiautocompletetextview中从下拉列表中删除分隔线 - How can I remove divider from dropdown in multiautocompletetextview in android in TokenAutoComplete 使用“MultiAutoCompleteTextView”时如何用空格替换逗号 - How to replace the comma with a space when I use the "MultiAutoCompleteTextView" 单击联系人时,如何检索联系人的详细信息? - How do I retrieve the details of an contact when i click on a contact? 我如何关闭该光标? - how do i close this cursor? 我如何在android数据绑定中绑定和调用`function type`? - How do i bind and invoke`function type` in android data binding?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM