我不知道为什么notifyDataSetChanged
在我的gridview中不起作用。我的改造事件onResponse
我调用该方法来刷新我的gridview项目并且没有任何变化......
改装电话
@Override
public void onResponse(Call<PictureInfos> call, Response<PictureInfos> response) {
PictureInfos infoResponse = response.body();
infoResponse.save();
pictureInfos.add(infoResponse);
adapter.updatePicturesList(pictureInfos);
}
Gridview BaseAdapter
public class ImageAdapter extends BaseAdapter {
private Context mContext;
private LayoutInflater mLayoutInflater;
private List<PictureInfos> mPInfoList;
public ImageAdapter(Context context, List<PictureInfos> pInfoList) {
mContext = context;
mPInfoList = pInfoList;
mLayoutInflater = LayoutInflater.from(context);
Log.v("5", "" + pInfoList.size());
}
public void updatePicturesList(List<PictureInfos> pInfoList) {
mPInfoList = pInfoList;
this.notifyDataSetChanged();
}
@Override
public int getCount() {
return mPInfoList.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View view;
final ImageView imageView;
final TextView legend;
// Soft display
if(convertView == null){
view = mLayoutInflater.inflate(R.layout.thumbnail_gallery, parent, false);
}else{
view = convertView;
}
// Get layout item (Image and Legend)
imageView = (ImageView) view.findViewById(R.id.iv_thumbnail);
legend = (TextView) view.findViewById(R.id.text_thumb);
// Get the download path image
String pic = Globals.SERVER_NAME+Globals
.ACCOUNT_SERVER_PATH+mPInfoList
.get(position).getFolderPath()+"/"+
VgzTools.addSuffix(mPInfoList.get(position).getFilename(), "-thumb");
Glide.with(mContext)
.load(pic)
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.into(imageView);
return view;
}
}
你有想法解决这个问题吗?
感谢。
答案 0 :(得分:1)
试试这个:
@Override
public void onResponse(Call<PictureInfos> call, Response<PictureInfos> response) {
PictureInfos infoResponse = response.body();
pictureInfos.clear();
pictureInfos.addAll(infoResponse);
adapter.notifyDataSetChanged();
}
答案 1 :(得分:-1)
当您将List<PictureInfos> mPInfoList
定义为最终版时,您将了解错误。