开发者

Android Image not loaded in Custom Adapter

I am having list of my Facebook friends and i created a list View that's having separator as months from Jan to Dec.

I am able list my friends details, My problem is that i am able to show their Name and birt开发者_开发问答hday date if i try load their "PICTURES" i can't do it..

It showing me the icon set as Background in XML.

Even the URL for the image to be load is get printed in Log, but i cant get the image..

Here is my code

 private class MyCustomAdapter extends BaseAdapter {
    private static final int TYPE_ITEM = 0;
    private static final int TYPE_SEPARATOR = 1;
    private static final int TYPE_MAX_COUNT = TYPE_SEPARATOR + 1;
    private LayoutInflater mInflater;
    private TreeSet<Integer> mSeparatorsSet = new TreeSet<Integer>();
    public MyCustomAdapter() {
        mInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mData = new ArrayList<Category>();
    }
    public void addItem(final Category item) {
        mData.add(item);
        notifyDataSetChanged();
    }
    public void addSeparatorItem(final Category item) {
        mData.add(item);
        // save separator position
        mSeparatorsSet.add(mData.size() - 1);
        notifyDataSetChanged();
    }
    @Override
    public int getItemViewType(int position) {
        return mSeparatorsSet.contains(position) ? TYPE_SEPARATOR : TYPE_ITEM;
    }
    @Override
    public int getViewTypeCount() {
        return TYPE_MAX_COUNT;
    }
    @Override
    public int getCount() {
        return mData.size();
    }
    @Override
    public Category getItem(int position) {
        return mData.get(position);
    }
    @Override
    public long getItemId(int position) {
        return position;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        int type = getItemViewType(position);
        System.out.println("getView " + position + " " + convertView + " type = " + type);
        Category category = mData.get(position);
        holder = new ViewHolder();
        if (convertView == null) {
             switch (type) {
                case TYPE_ITEM:
                    convertView = mInflater.inflate(R.layout.item1, null);
                    holder.textView = (TextView)convertView.findViewById(R.id.text);
                    holder.textView1 = (TextView)convertView.findViewById(R.id.text1);
                    holder.icon = (ImageView) convertView.findViewById(R.id.friend_photo);
                    break;
                case TYPE_SEPARATOR:
                    convertView = mInflater.inflate(R.layout.item2, null);
                    holder.textView = (TextView)convertView.findViewById(R.id.textSeparator);
                    break;
            }
            convertView.setTag(holder);
        } else {
            if(type==TYPE_ITEM){
                 holder.textView = (TextView)convertView.findViewById(R.id.text);
                 holder.textView1 = (TextView)convertView.findViewById(R.id.text1);
                 holder.icon = (ImageView) convertView.findViewById(R.id.friend_photo);
                 holder = (ViewHolder)convertView.getTag();
            }else{
                 holder.textView = (TextView)convertView.findViewById(R.id.textSeparator);
                 holder = (ViewHolder)convertView.getTag();
            }

        }
        if(type==TYPE_SEPARATOR){
             holder.textView.setText(mData.get(position).dealTitle);
        }else{
             holder.textView.setText(mData.get(position).dealTitle);
              holder.textView1.setText(mData.get(position).dealDesc);
              holder.icon.setTag(mData.get(position).picture);
        }


        return convertView;
    }

}


You need to set your ImageView's bitmap using one of the setImageFoo() calls.

  • setImageResource()
  • setImageBitmap()
  • setImageDrawable()


I'm not sure what type of object mData.get(position).picture is but

holder.icon.setTag(mData.get(position).picture);

isn't loading the picture. That's just setting some data on the View. You need to use one of the setImage() methods of ImageView.


Your code looks fine, there might be a problem with the xml/layout file.

As you are loading two textViews and a ImageView from the xml for each item, it is important to know how the layout is organised to show all the added views in it.

Please post the layout files so that, one can suggest if there is any problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜