我有我的 Facebook 朋友的列表,我创建了一个列表视图,从一月到十二月有几个月的分隔符。
我可以列出我朋友的详细信息,我的问题是,如果我尝试加载他们的“图片”,我可以显示他们的姓名和生日日期,但我做不到。
它向我展示了在 XML 中设置为背景的图标。
甚至要加载的图像的 URL 也打印在日志中,但我无法获取图像..
这是我的代码
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;
}
}