2016-04-14 45 views
1

私は単純なタスクを持っていますが、なぜ動作しないのか分かりません。 GridViewimagesを配置する必要があります。私はRecyclerViewを使用することに決めました。だから私はいくつかの私はそれを配置したた場所:私はデータ取得Retrofit2を使用して、すべての私のviewsobjectsが初期化されているRecyclerViewはまったく更新されません

images = new ArrayList<>(); 
    recyclerView = (RecyclerView) findViewById(R.id.my_recycler_view1); 

    adapter = new ImageGridAdapter(Place.this, images); 
    manager = new GridLayoutManager(this, 3); 
    recyclerView.addItemDecoration(new GridSpacingItemDecoration(3, 8, true)); // for grid with equal spacing 
    recyclerView.setLayoutManager(manager); 
    recyclerView.setHasFixedSize(true); 
    recyclerView.setAdapter(adapter); 

とアダプタを更新しよう:

<LinearLayout 
    ..> 
    ... 

<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#ebebeb"> 
    <android.support.v7.widget.RecyclerView 
     android:id="@+id/my_recycler_view1" 
     android:scrollbars="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 
</FrameLayout> 
</LinearLayout> 

を私Activityでは、私は宣言する、前に作成されます。

 @Override 
     public void onResponse(Call<PlaceModel> call, Response<PlaceModel> response) { 
      placeProperties = response.body().getData(); 
      images = placeProperties.getPhotos(); 
      System.out.println("size = " + images.size()); 
      handler.post(new Runnable() { 
       @Override 
       public void run() { 
        updateUI(placeProperties); 

        images.clear(); 
        images.addAll(placeProperties.getPhotos()); 
        adapter.notifyItemChanged(0, images.size()); 
        //just adapter.notifyDataSetChanged(); also doesn't give result; 

       } 
      }); 

     } 

それにもかかわらず、私のupdateUI方法はplacePropertiesオブジェクトからのデータで正常に動作し、アップデートを望みます。そして、image.size()>1

ここにはAdapterクラスがあります。 https://gist.github.com/burnix/aa27efe9586213852c108f3d79f3f69d

ログによれば、私のonBindViewHolderメソッドは機能しません。

私は何を欠席しましたか?なぜ私のRecyclerViewは画像を表示しないのですか?

P.S.私はすべての似たような質問を読んだが、助けにはならない。私はちょうど疲れて、とても単純なものを無視しているといいですね...

+0

は)(onResponseにこの行をコメントアウトしてみてください。 '//イメージ=のplaceProperties.getPhotos();' –

+0

@DanielNugent、あなたがそうしていますスマートで行き届いた!それは仕事です;) –

答えて

1

なぜ機能しないのは、RecylerViewのデータソースの参照を再割り当てしていることです。

あなたがする必要があるのは、この行を削除します

images = placeProperties.getPhotos(); 
+0

ありがとうございます。私はそれを持っている! –

関連する問題