Android的负荷联系人照片到列表

Android的负荷联系人照片到列表

本文介绍了Android的负荷联系人照片到列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我有这个code:`公共类MaxsapListAdapter延伸BaseAdapter {

Hello I have this code:`public class MaxsapListAdapter extends BaseAdapter {

    private LayoutInflater mInflater;
    private Bitmap mIcon1;
    private Bitmap mIcon2;
    private Bitmap mIconCall;
    private String[] DATA;

    MaxsapListAdapter(Context context, String[] DATA) {
        // Cache the LayoutInflate to avoid asking for a new one each time.
        mInflater = LayoutInflater.from(context);

        // Icons bound to the rows.
        mIcon1 = BitmapFactory.decodeResource(context.getResources(),
                R.drawable.icon48x48_1);
        mIcon2 = BitmapFactory.decodeResource(context.getResources(),
                R.drawable.icon48x48_2);
        mIconCall = BitmapFactory.decodeResource(context.getResources(), R.drawable.call);
        this.DATA = DATA;
    }

    /**
     * The number of items in the list is determined by the number of speeches
     * in our array.
     *
     * @see android.widget.ListAdapter#getCount()
     */
    public int getCount() {
        return DATA.length;
    }

    /**
     * Since the data comes from an array, just returning the index is sufficent
     * to get at the data. If we were using a more complex data structure, we
     * would return whatever object represents one row in the list.
     *
     * @see android.widget.ListAdapter#getItem(int)
     */
    public Object getItem(int position) {
        return position;
    }

    /**
     * Use the array index as a unique id.
     *
     * @see android.widget.ListAdapter#getItemId(int)
     */
    public long getItemId(int position) {
        return position;
    }

    /**
     * Make a view to hold each row.
     *
     * @see android.widget.ListAdapter#getView(int, android.view.View,
     *      android.view.ViewGroup)
     */
    public View getView(int position, View convertView, ViewGroup parent) {
        // A ViewHolder keeps references to children views to avoid unneccessary
        // calls
        // to findViewById() on each row.
        ViewHolder holder;

        // When convertView is not null, we can reuse it directly, there is no
        // need
        // to reinflate it. We only inflate a new View when the convertView
        // supplied
        // by ListView is null.
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.list_item_icon_text, null);

            // Creates a ViewHolder and store references to the three children
            // views
            // we want to bind data to.
            holder = new ViewHolder();
            holder.text = (TextView) convertView.findViewById(R.id.text);
            holder.icon = (ImageView) convertView.findViewById(R.id.icon);
            holder.btn = (ImageButton) convertView.findViewById(R.id.button);
            convertView.setTag(holder);
        } else {
            // Get the ViewHolder back to get fast access to the TextView
            // and the ImageView.
            holder = (ViewHolder) convertView.getTag();
        }
        // Bind the data efficiently with the holder.
        holder.text.setText(DATA[position]);
        holder.icon.setImageBitmap((position & 1) == 1 ? mIcon1 : mIcon2);
        holder.btn.setImageBitmap(mIconCall);
        holder.btn.setId((int)this.getItemId(position));
        holder.btn.setFocusable(false);
        holder.btn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                      Log.e("maxsap","--------*ButtonClicked*---------");
              Log.e("maxsap","--------"+v.setTag(key, tag)+"---------");
        Intent callIntent = new Intent(v.getContext(),PhoneCall.class);
                Log.e("maxsap",PhoneCall.class.toString());
                startActivity(callIntent);
            }
        });
        return convertView;
    }

     class ViewHolder {
        TextView text;
        ImageView icon;
        ImageButton btn;
    }
}`

它加载名单上的一些任意数据阵列,并设置一些示例图标太多,我希望能够在我名单上使用用户的联系人旁边用户

例如命名通讯录用户有他的手机上,并在每一个接触,有一个照片负荷的照片旁边的联系人的名字加载其他空白的形象,这是可能的名单将尽可能多的行?怎么样?

which loads some arbitrary data array on a list and sets some example icons too,I would like to be able to use users contacts on my list next to users name e.g. the list will be as many rows as contacts user has on his phone and in every contact that there is a photo load that photo next to contacts name else load a blank image, is this possible? and how?

推荐答案

如果您要添加的联系人和照片到您的列表,你需要访问联系人API。

If you want to add contacts and photos to your list you'll need to access the Contacts API.

有关Android的版本到1.6,你会使用Contacts.People和2.0和更大的,你会想利用ContactsContract.Contacts的。这两种会给你访问到联系人的显示名称和默认照片。

For android versions up to 1.6 you'll be using Contacts.People and for 2.0 and greater you'll want to make use of ContactsContract.Contacts. Both of these will give you access to the contact display name and default photo.

有很多围绕着如何利用这些,包括对Android现场一些官方的人的例子。

There are plenty of examples around of how to make use of these, including some official ones on the android site.

这里是一个应该让你开始在新的联系模型中的文章:

Here's an article that should get you started on the new contacts model:http://developer.android.com/resources/articles/contacts.html

它包括了一些有用的code片段,应该帮助您开始。

It includes some useful code snippets that should help you get started.

哦,不要忘了添加权限在您的清单中显示联系人。 :)

Oh, Don't forget to add permissions for displaying contacts in your manifest. :)

这篇关于Android的负荷联系人照片到列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 21:12