Android auto-complete components (SocialTokenAutoComplete)-a more friendly way @ someone in social apps, android four components

Source: Internet
Author: User

Android auto-complete components (SocialTokenAutoComplete)-a more friendly way @ someone in social apps, android four components


Project address: https://github.com/bitjjj/SocialTokenAutoComplete


Sample Code:


public class SocialTokenActivity extends Activity {    SocialContactsCompletionView completionView;    Contact[] people;    ArrayAdapter<Contact> adapter;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_demo);        people = new Contact[]{                new Contact("Marshall Weir", "marshall@example.com",R.drawable.author0),                new Contact("Margaret Smith", "margaret@example.com",R.drawable.author1),                new Contact("Max Jordan", "max@example.com",R.drawable.author2),                new Contact("Meg Peterson", "meg@example.com",R.drawable.author3),                new Contact("Amanda Johnson", "amanda@example.com",R.drawable.author4),                new Contact("Terry Anderson", "terry@example.com",R.drawable.author0)        };        adapter = new FilteredArrayAdapter<Contact>(this, R.layout.contact_layout, people) {            @Override            public View getView(int position, View convertView, ViewGroup parent) {                if (convertView == null) {                    LayoutInflater l = (LayoutInflater)getContext().getSystemService(Activity.LAYOUT_INFLATER_SERVICE);                    convertView = (View)l.inflate(R.layout.contact_layout, parent, false);                }                Contact p = getItem(position);                ((TextView)convertView.findViewById(R.id.name)).setText(p.getName());                ((ImageView)convertView.findViewById(R.id.icon_image)).setBackgroundResource(p.getIcon());                ((TextView)convertView.findViewById(R.id.email)).setText(p.getEmail());                return convertView;            }            @Override            protected boolean keepObject(Contact obj, String mask) {                mask = mask.toLowerCase(Locale.getDefault());                return mask.contains("@") && obj.getName().toLowerCase(Locale.getDefault()).startsWith(mask.substring(mask.lastIndexOf("@")+1));            }        };        completionView = (SocialContactsCompletionView)findViewById(R.id.searchView);        completionView.setAdapter(adapter);        if (savedInstanceState == null) {            //completionView.setPrefix("To: ");            //completionView.addObject(people[0]);            //completionView.addObject(people[1]);        }                  }    private void updateTokenConfirmation() {        StringBuilder sb = new StringBuilder("Current tokens:\n");        for (Object token: completionView.getObjects()) {            sb.append(token.toString());            sb.append("\n");        }    }   }





Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.