-3

我使用自定义适配器使用图像 url 显示图像。有时它工作正常,但有时 getview() 没有被调用。我从我的代码中找不到任何错误。

public class GridViewAdapter  extends ArrayAdapter<ListViewVariables> {

private final Activity context;
private final List<ListViewVariables> list;
DisplayImageOptions doption=null;
private ImageLoadingListener animateFirstListener =null;
ImageLoader imageLoader= null;

public GridViewAdapter(Activity context, List<ListViewVariables> list) {
    super(context, R.layout.list_layout, list);
    this.context = context;
    this.list = list;
}
@Override
public int getCount() {
    // TODO Auto-generated method stub
    return list.size();
}

@Override
public ListViewVariables getItem(int position) {
    // TODO Auto-generated method stub
    return list.get(position);
}

@Override
public long getItemId(int position) {
    // TODO Auto-generated method stub
    return position;
}

static class ViewHolder {

    protected ImageView image;

}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View view = null;
    if (convertView == null) {
        LayoutInflater inflator = context.getLayoutInflater();
        view = inflator.inflate(R.layout.list_layout, null);
        final ViewHolder viewHolder = new ViewHolder();
        viewHolder.image = (ImageView) view.findViewById(R.id.image);

        view.setTag(viewHolder);
    } else {
        view = convertView;
    }
    ViewHolder holder = (ViewHolder) view.getTag();
  imageLoader = ImageLoader.getInstance();
    imageLoader.init(ImageLoaderConfiguration.createDefault(context));
    imageLoader.displayImage(list.get(position).getImageUrl(), holder.image,doption,animateFirstListener);
    return view;

}

为了显示图像,我正在使用图像加载器和调用函数如下:

list = EventManagementResuableClass.getResponseFromServer(
                    EventManagenmentConstant.responseStatus_object,
                    EventActivity.this, jsonObj);
            adapter = new GridViewAdapter(EventActivity.this, list);
            adapter.clear();
            adapter.notifyDataSetChanged();
            listView.setAdapter(adapter);

通常我会得到清单。但某些时候 getview() 似乎没有被执行。确切的问题是什么?

4

1 回答 1

0

为什么你有以下几行?

adapter.clear();
adapter.notifyDataSetChanged();

尝试不使用这些线条...

于 2014-06-05T09:55:57.507 回答