Selecting Contact from Autocomplete Textview

selecting contact from autocomplete textview

Add a onItemClickListener for the AutoCompleteTextView instead of having it as a seperate function.

 mTxtPhoneNo.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> av, View arg1, int index,
long arg3) {
Map<String, String> map = (Map<String, String>) av.getItemAtPosition(index);

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

}

});

or implement OnItemClickListener for your activity and set

mTxtPhoneNo.setOnItemClickListener(this);

How to select multiple contact in autocompletetextview

Instead of writing a logic for selecting multiple contacts using ListView, we can simply use MultiAutoCompleteTextView.The code is as same as for the AutoCompleteTextView.Through this we can select multiple contacts.

how to select multiple contacts in autocomplet textview?

May This Help you:

Buddy Use MultiAutoCompleteTextView instead of AutoCompleteTextView

For Reference: Click Here

AutoComplete TextView with Contacts

Try the following:

ArrayList<String> emailAddressCollection = new ArrayList<String>();

ContentResolver cr = getContentResolver();

Cursor emailCur = cr.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, null, null, null, null);

while (emailCur.moveToNext())
{
String email = emailCur.getString(emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
emailAddressCollection.add(email);
}
emailCur.close();

String[] emailAddresses = new String[emailAddressCollection.size()];
emailAddressCollection.toArray(emailAddresses);

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, emailAddresses);
AutoCompleteTextView textView = (AutoCompleteTextView)findViewById(R.id.YOUR_TEXT_VIEW);
textView.setAdapter(adapter);
}

Note: Don't forget to add the READ_CONTACTS permission to your Manifest.xml:

<uses-permission android:name="android.permission.READ_CONTACTS" />

get the selected contact phone numbers from multi autocomplete textview

I solved the multi-autocomplete OnItemclickListener issue by changing the code as below

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// TODO Auto-generated method stub

TextView temp = (TextView) view.findViewById(R.id.ccontNo);
TextView temp2 = (TextView) view.findViewById(R.id.ccontName);
final String selectedNumber = temp.getText().toString();
final String selectedName = temp2.getText().toString();

if (selectedNumber != null) {

InputMethodManager imm = (InputMethodManager) getSystemService(
INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);

// Show Alert
Toast.makeText(getBaseContext(), " Name:"+selectedName+" Number:"+selectedNumber, Toast.LENGTH_LONG).show();

}
}

Now i am getting the selected contact name and number. Then store those values in HashMap and while button click split the selected contacts by "," and iterate the loop for each name to get the contact number.

In this way i solved my problem hope it is helpful !! if so up Vote the answer!!!

AutoCompleteTextView - Show suggestions after selection

write below code in your AutoCompleteTextView.setOnItemClickListener()

autoComplete.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
autoComplete.postDelayed(new Runnable() {
@Override
public void run() {
autoComplete.showDropDown();
}
},100);
autoComplete.setText(autoComplete.getText().toString());
autoComplete.setSelection(autoComplete.getText().length());

}
});

And that's it, it will work like charm!!!

This will give you hint for your question, change according to your need and adapter data



Related Topics



Leave a reply



Submit