0

我想在 ListView 中更改 ImageView 中的图像,但它不起作用。

Bellow 是我的数据和列表适配器。

public class Archivedata {
    public String mTo = "";
public ImageView mImage;
public int mID = 0;
public String mText = "";
public String mDate;

}



public class ArchiveListAdapter extends BaseAdapter{
    private LayoutInflater mInflater;
private Vector<Archivedata> mArchiveVector;


public ArchiveListAdapter(Context context, final Vector<Archivedata> data) {
    mArchiveVector = data;
    mInflater = LayoutInflater.from(context);
}

public int getCount() {
    return mArchiveVector.size();
}

public Object getItem(int position) {
    return mArchiveVector.elementAt(position);
}

public long getItemId(int position) {
    return position;
}

public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
            if (convertView == null) {
        convertView = mInflater.inflate(R.layout.archive, null);
                holder = new ViewHolder();
        holder.mTxtArchiveDate = (TextView) convertView.findViewById(R.id.date);
        holder.mTxtArchiveText = (TextView) convertView.findViewById(R.id.txtArchiveText);
            holder.mImage = (ImageView) convertView.findViewById(R.id.list_image);
        holder.mTxtArchiveTo = (TextView) convertView.findViewById(R.id.toname);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    Archivedata data = mArchiveVector.elementAt(position);

    holder.mTxtArchiveDate.setText(data.mDate);
    holder.mTxtArchiveText.setText(data.mText);         
    holder.mImage.setImageResource(R.drawable.anonymous_logo);
    holder.mTxtArchiveTo.setText(data.mTo);
        return convertView;
}

    private class ViewHolder {
     TextView mTxtArchiveTo;
     ImageView mImage;
     TextView mTxtArchiveText;
     TextView mTxtArchiveDate;
}

}

这是更新图像的活动中的代码:

private Archives mArchive;
private ArchiveListAdapter mArchiveListAdapter;

for (int i = 0; i < mArchive.mArchive.size(); ++i) {
    Bitmap im = getFacebookPhoto(mArchive.mArchive.elementAt(i).mTo);   
    mArchive.mArchive.elementAt(i).mImage.setImageBitmap(im);
}
mArchiveListAdapter = new ArchiveListAdapter(getActivity(),mArchive.mArchive);
mArchiveListAdapter.notifyDataSetChanged();
mScrollView.setAdapter(mArchiveListAdapter);

它在以下行返回错误:

mArchive.mArchive.elementAt(i).mImage.setImageBitmap(im);

有人可以帮我吗?

谢谢

4

1 回答 1

0

我认为顺序是错误的:

在里面:

mArchiveListAdapter = new ArchiveListAdapter(getActivity(),mArchive.mArchive);
mScrollView.setAdapter(mArchiveListAdapter);

更新:

for (int i = 0; i < mArchive.mArchive.size(); ++i) {
    Bitmap im = getFacebookPhoto(mArchive.mArchive.elementAt(i).mTo);   
    mArchive.mArchive.elementAt(i).mImage.setImageBitmap(im);
}
if(mArchiveListAdapter!=null){
    mArchiveListAdapter.notifyDataSetChanged();
} else {
    //fallback
     mArchiveListAdapter = new ArchiveListAdapter(getActivity(),mArchive.mArchive);
     mScrollView.setAdapter(mArchiveListAdapter);
}

可能给了你一些建议。

于 2013-08-15T20:14:38.493 回答