0

嗨,我有以下代码。现在我只需要将电话号码带入自动完成文本框...如何做到这一点

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

    mPeopleList = new ArrayList<Map<String, String>>();
    PopulatePeopleList();
    mTxtPhoneNo = (AutoCompleteTextView) findViewById(R.id.mmWhoNo);

    mAdapter = new SimpleAdapter(this, mPeopleList, R.layout.custcontview,
            new String[] {"Name","Phone","Type"}, new int[] {R.id.ccontName,R.id.ccontNo,R.id.ccontType});

    mTxtPhoneNo.setAdapter(mAdapter);

}

public void PopulatePeopleList() {

    mPeopleList.clear();

    Cursor people = 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 = 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));

                Map<String, String> NamePhoneType = new HashMap<String, String>();

                NamePhoneType.put("Name", contactName);
                NamePhoneType.put("Phone", phoneNumber);

                if (numberType.equals("0"))
                    NamePhoneType.put("Type", "Work");
                else if (numberType.equals("1"))
                    NamePhoneType.put("Type", "Home");
                else if (numberType.equals("2"))
                    NamePhoneType.put("Type", "Mobile");
                else
                    NamePhoneType.put("Type", "Other");

                // Then add this map to the list.
                mPeopleList.add(NamePhoneType);
            }
            phones.close();
        }
    }
    people.close();

    startManagingCursor(people);
}

}

它以这种格式返回 Name=xyz.Type=Mobile,Number=1234.... 我只需要获取的号码并将该号码用于我的程序的进一步添加代码以获取号码的位置。

4

2 回答 2

1

只用这条线

String phoneNumber = phones
                        .getString(phones
                                .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));


            NamePhoneType.put("Phone", phoneNumber);

您正在输入所有数据,包括名称,类型..只放电话看看

于 2013-05-23T04:45:06.487 回答
0

*你可以试试这个代码 *

<AutoCompleteTextView
android:id="@+id/AfromACT"
android:layout_width="150px"
android:layout_height="40px"
android:layout_marginLeft="10px"
android:layout_marginTop="15px"
android:background="#FFFFFF"
android:textColor="#000000" 
android:singleLine="true"
android:inputType="textVisiblePassword"
android:textCursorDrawable="@null"
android:paddingLeft="5px"

android:inputType="手机" android:textSize="17px" />

于 2013-05-23T04:44:31.013 回答