2016-03-22 3 views
0

なぜnotifyDataSetChangedが私のgridviewで動作しないのかわかりません。 IですかAndroidのnotifyDataSetChangedがグリッドビューで機能しない

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; 
    } 
} 

レトロフィットコール

@Override 
public void onResponse(Call<PictureInfos> call, Response<PictureInfos> response) { 
    PictureInfos infoResponse = response.body(); 

    infoResponse.save(); 
    pictureInfos.add(infoResponse); 
    adapter.updatePicturesList(pictureInfos); 
} 

GridViewのBaseAdapter

...私の改造イベントonResponseは、私は私のGridViewの項目を更新するメソッドを呼び出し、変更はありませんそれを修正するアイデアはありますか?

ありがとうございました。

+0

サーバーの応答を確認しましたか?あなたはより多くの物を持っていますか? –

+0

もちろん、私は良い応答を得ます – John

答えて

1

はこれを試してください:あなたは、最終的なようList<PictureInfos> mPInfoListを定義するとき

@Override 

public void onResponse(Call<PictureInfos> call, Response<PictureInfos> response) { 
    PictureInfos infoResponse = response.body(); 
pictureInfos.clear(); 
pictureInfos.addAll(infoResponse); 
adapter.notifyDataSetChanged(); 
} 
+0

私はすでにこれを試しましたが、これは私にリストサイズ= 0を返します。 – John

+0

あなたのコードをデバッグし、infoResponseともう一つのものにどんな値が入っているのかを調べてください。 – Nidhi

+0

オン応答が良好です。私はすべてのデータを持っています。しかし、私が.clear()を実行すると、このアクティビティのすべてのList がリセットされます。 – John

0

はあなたが間違っているかを理解します。

+0

あなたはより具体的になることができますか? – temirbek

関連する問題