Search code examples
androidandroid-layoutcontact-formtag-cloudword-cloud

Gmail like contact selector / tag cloud / chip cloud with profile image android


My goal

enter image description here

To create a contact picker (with round image on the left) like gmail does when sending an email. I've done some research finding an EditText cloud and a Chip Cloud, but they do not support images in custom layouts and the adapter only accepts List<String>. Does someone have a proper idea of how to implement this or use a library to implement this.

Thanks in advance.


Solution

  • I suggest you to use TokenAutoComplete

    public class ContactsCompletionView extends TokenCompleteTextView<Person> {
        public ContactsCompletionView(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        @Override
        protected View getViewForObject(Person person) {
    
            LayoutInflater l = (LayoutInflater) getContext().getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
            TextView view = (TextView) l.inflate(R.layout.contact_token, (ViewGroup) getParent(), false);
            view.setText(person.getEmail());
    
            return view;
        }
    
        @Override
        protected Person 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);
            }
        }
    }
    

    OUTPUT:

    enter image description here