码迷,mamicode.com
首页 > 移动开发 > 详细

Android 自动完全组件(SocialTokenAutoComplete)—— 一种更友好的方式@某人在社交应用中

时间:2014-09-25 16:52:04      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:java   android   社交应用   

bubuko.com,布布扣


项目地址:https://github.com/bitjjj/SocialTokenAutoComplete


代码示例:


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


   
}


Android 自动完全组件(SocialTokenAutoComplete)—— 一种更友好的方式@某人在社交应用中

标签:java   android   社交应用   

原文地址:http://blog.csdn.net/kittyjie/article/details/39552691

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!