重写SimpleAdapter以让其中的imageview显示bitmap,怎么解决

下面是我重写simpleadapter的代码,其主要作用是显示返回的bitmap图片,求大神看看哪里不对
if (msg.arg1 == 0X456) {
listItems= (List>) msg.obj;
// 创建一个SimpleAdapter实现界面的更新
SimpleAdapter simpleAdapter = new SimpleAdapter(getActivity(), listItems, R.layout.news_simple_item,
new String[]{"image", "title", "abs"},
new int[]{R.id.image, R.id.title, R.id.abs});
simpleAdapter.setViewBinder(new SimpleAdapter.ViewBinder(){

                @Override
                public boolean setViewValue(View view, Object data,
                                            String textRepresentation) {
                    if( (view instanceof ImageView) & (data instanceof Bitmap) ) {
                        ImageView iv = (ImageView) view;
                        Bitmap bm = (Bitmap) data;
                        iv.setImageBitmap(bm);
                        return true;
                    }
                    return false;

                }

3个回答

public class MyPopWindowAdapter extends BaseAdapter {

    private Context mContext;
    private List<String> mList;

    public MyPopWindowAdapter(Context context , List<String> list ) {
        this.mContext = context;
        this.mList = list;
    }

    public void setmList(List<String> mList,int index) {
        this.mList = mList;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

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

    @SuppressLint({ "ResourceAsColor", "InflateParams" })
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder mViewHolder;
        if (convertView == null ) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.popspinner_popwindow_list_item, null);
            mViewHolder = new ViewHolder();
            mViewHolder.mTextView = (TextView) convertView.findViewById(R.id.popwindow_list_item_tv);
            convertView.setTag(mViewHolder);
        }else {
            mViewHolder = (ViewHolder) convertView.getTag();
        }
        mViewHolder.mTextView.setText(mList.get(position));
        //在这里给Imageview加载bitmap就ok了
        return convertView;
    }
    private class ViewHolder {
        private TextView mTextView;
    }
}

我把获取到的bitmap已经放到了image中,可是不显示所以我写了一setViewBinder以显示biemap图片,可是返回的却是false,怎么回事,求大神解答

既然return了false,说明if判断里面的参数没按照流程走完。还有个问题:if判断为何不用&& 而要选择用&我很疑问。

qq_28026283
大白大白大白 不知道你需要的是哪种,我贴了个最简单的自定义adapter
3 年多之前 回复
a179583637
a179583637 &这个是我的错,我已经改好了,可是还是不好使,我看了一下得自己写适配器才能解决,能教教我怎么写自定义的apapter嘛
3 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问