0

MultiAutoCompleteTextView에 대해 mutliple 연락처를 반환하도록 AutoCompleteTextView에 대한 stackoverflow에서 본 코드를 수정하려고합니다.여러 연락처를 검색하는 Android MultiAutoCompleteTextView

그러나 Android 휴대 전화에 이것을로드하면 더 이상 선택할 수있는 추천을 볼 수 없습니다. 나는 ArrayAdapter 초기화 문제가 있다고 느끼지만, 무엇이 잘못되었는지 알 수 없다.

미리 도움을 청하십시오.

<MultiAutoCompleteTextView 
    android:id="@+id/mmWhoNo" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:textColor="#0000A0" 
    android:hint="Choose your Contacts" /> 

을 마지막으로 나는 내가 수정의 조금으로 selecting contact from autocomplete textview 걸릴 한 내 연락처를 읽고 다음 한 :

내 multiautocompletetextview을 위해 다음과 같은 코드가 있습니다.

private ArrayList<Map<String, String>> mPeopleList; 
private ArrayAdapter mAdapter; 
private MultiAutoCompleteTextView mTxtPhoneNo; 

     mPeopleList = new ArrayList<Map<String, String>>(); 
     PopulatePeopleList(); 
    mTxtPhoneNo = (MultiAutoCompleteTextView) findViewById(R.id.mmWhoNo); 
    mTxtPhoneNo.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer()); 
    mTxtPhoneNo.setThreshold(1); 

      //just to check to see that mPeopleList is being populated 
    Log.i("Multiplecontacts",mPeopleList.get(0).toString()); 


    mAdapter = new ArrayAdapter<ArrayList<Map<String,String>>>(this, android.R.layout.simple_dropdown_item_1line); 
    mAdapter.add(mPeopleList); 

    mTxtPhoneNo.setAdapter(mAdapter); 

    mTxtPhoneNo 
      .setOnItemClickListener(new OnItemClickListener() { 

       @Override 
       public void onItemClick(AdapterView<?> av, View arg1, 
         int index, long arg3) { 
        // TODO Auto-generated method stub 
        Map<String, String> map = (Map<String, String>) av 
          .getItemAtPosition(index); 

        String name = map.get("Name"); 
        String number = map.get("Phone"); 
        mTxtPhoneNo.setText("" + name + "<" + number + ">,"); 

       } 


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); 
} 

      }); 

답변

0

문제는 ArrayAdaptor를 사용하고 있기 때문에 발생합니다. 양식을 선택하기 위해 Map 목록을 제공하지만 맵 개체를 입력 텍스트와 비교하거나 필터링하는 방법에 대한 데이터는 제공하지 않습니다. 대신 SimpleAdapter를 사용했는데 정상적으로 작동했습니다.

mTxtPhoneNo = (MultiAutoCompleteTextView) findViewById(R.id.multiAutoCompleteTextViewContactsNames); 
mAdapter = new SimpleAdapter(this, mPeopleList, R.layout.costom_contact_view, new String[] { "Name", "Phone", "Type" }, new int[] { 
          R.id.ccontName, R.id.ccontNo, R.id.ccontType }); 
mTxtPhoneNo.setThreshold(1); 
mTxtPhoneNo.setAdapter(mAdapter); 
mTxtPhoneNo.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer()); 
mTxtPhoneNo.setOnItemClickListener(multiAutoContactNamesListener); 

또한 OnClickListener에서 연락처의 이름을 연결해야합니다. 변경 :

mTxtPhoneNo.setText("" + name + "<" + number + ">,"); 

사람 :이 도움이

mTxtPhoneNo.append(", " + name + " <" + number + ">"); 

희망.

2

나는 ArrayAdapter 유형에 ArrayList<Map<String, String>>을 사용하는 대신 ContactsInfo라는 클래스를 만든 다음 ArrayAdapter<ContactsInfo>을 만들었습니다.

마찬가지로 ArrayList<Map<String, String>>ArrayList<ContactsInfo>으로 변경하면 효과가있었습니다.

또한 ContactsInfo 클래스의 toString 메서드를 덮어 써야합니다.

+0

나는 당신이 제공 한 것과 똑같은 예제와 잘 작동한다. 그러나 문제는 쉼표가 표시되지 않는다는 것입니다. 수동으로 추가해야합니다. –