BaseaAdapter中的GetView()无法正常工作

时间:2015-06-27 16:01:21

标签: android baseadapter getview

我需要做一个ListView,在每个项目中它最多可以显示9张图片。所以我认为带有GirdView的ListView可能有效。但问题是,当我第一次从服务器获取图像时,它没有运行。但是当我滚动(它没有屏幕)并向后滚动时。图像消失但TextView没有错。我能找到原因。

这是GirdView的BaseAdapter:

class NoScrollGridAdapter extends BaseAdapter{

    private Context mContext;

    private ArrayList<String> items;



    public NoScrollGridAdapter(Context ctx, ArrayList<String> items) {

        this.mContext = ctx;

        this.items = items;

    }

    @Override

    public int getCount() {

        // TODO Auto-generated method stub

        Log.v("getCount",items.size()+"");

        return items.size();

    }



    @Override

    public Object getItem(int position) {

        // TODO Auto-generated method stub

        return items.get(position);

    };

    @Override

    public long getItemId(int position) {

        // TODO Auto-generated method stub

        return position;

    }



    @Override

    public View getView(int position, View convertView, ViewGroup parent) {

        // TODO Auto-generated method stub

         ViewHolder2 holder2;

         //View view = View.inflate(mContext, R.layout.image_item, null);

         if (convertView == null) {

                holder2 = new ViewHolder2();

                convertView = View.inflate(mContext, R.layout.image_item, null);

                holder2.item= (NetworkImageView) convertView.findViewById(R.id.itemImage);

                convertView.setTag(holder2);

         }

         else{

             holder2 = (ViewHolder2) convertView.getTag(); 

         }

         String dataString=items.get(position); 

         holder2.item.setDefaultImageResId(R.drawable.moren); 

         holder2.item.setErrorImageResId(R.drawable.moren); 

         ImageLoader imageLoader = new ImageLoader(Merchant_main.BBQueue, localStore.storeCache); 

         holder2.item.setImageUrl(dataString,imageLoader);

        return convertView;

    }



}

static class ViewHolder2 {

    private NetworkImageView item;

}

在listView的BaseAdapter中,在getView()中我绑定了这个

中的adpter
    NoScrollGridAdapter gridAdapter=new       NoScrollGridAdapter(getActivity(),imageUrls);

            gridview.setAdapter(gridAdapter);

            gridAdapter.notifyDataSetChanged();

0 个答案:

没有答案