最近文章


联系我们
最近文章
您当前位置:主页 > 最近文章 >

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

发布时间:2019-02-06 编辑:admin

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


项目地址: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", "[email protected]",R.drawable.author0),
                new Contact("Margaret Smith", "[email protected]",R.drawable.author1),
                new Contact("Max Jordan", "[email protected]",R.drawable.author2),
                new Contact("Meg Peterson", "[email protected]",R.drawable.author3),
                new Contact("Amanda Johnson", "[email protected]",R.drawable.author4),
                new Contact("Terry Anderson", "[email protected]",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:
");
        for (Object token: completionView.getObjects()) {
            sb.append(token.toString());
            sb.append("
");
        }
    }


   
}





http://www.bkjia.com/Androidjc/885351.htmlwww.bkjia.comtruehttp://www.bkjia.com/Androidjc/885351.htmlTechArticleAndroid 自动完全组件(SocialTokenAutoComplete)—— 一种更友好的方式@某人在社交应用中,android四大组件 项目地址:https://github.com/bitjjj/Socia...

本文源自: 环亚娱乐


上一篇:quick-cocos2d-x游戏开发【11】——多点触摸,quickcocos2d

下一篇:没有了


Copyright © 2005-2016 http://www.croeterink.com 环亚娱乐_真人官网娱乐_环亚科技_腾讯新闻版权所有 环亚娱乐_真人官网娱乐_环亚科技_腾讯新闻