2016-06-18 7 views
0

ネストされたビューを処理するために、どのようにアンドロイドRecyclerView、私は1つのアダプタJSONを持つ複雑ますが、画像の複数の時間リピートRecyclerViewアーキテクチャ

"id": "c200", 
      "name": "Ravi Tamada", 
      "email": "[email protected]", 
      "address": "xx-xx-xxxx,x - street, x - country", 
      "gender" : "male", 
      "phone": [{ 
       "image": "image.png", 
       "image": "image.png", 
       "image": "image.png" 
      }} 
      } 

あなたは画像に

enter image description here

+0

私はあなたが複数のイメージのために、すべての内部ロジックを処理する必要があり、そのためのカスタムレイアウトを作成するべきだと思います。 –

答えて

0

を表示する方法2つの選択肢があります。

  1. あなたのカードの内側のLinearLayoutを使用して、あなたのカードの内側RecyclerViewを使用することができますImageViewの
  2. を含むcustomLayoutを膨らませることができます。あなたは、既存の内部で別のRecyclerViewを使用することができます

    - オプション2を説明

cardView - 親recyclerViewため

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.CardView 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/ViewAllLayout" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:background="#ffffff" 
android:orientation="vertical" 
android:paddingBottom="8dp"> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 
. 
. 
. 
. 

<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/recyclerView" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:paddingLeft="4dp" 
    android:paddingRight="4dp" 
    android:paddingTop="4dp"/> 
. 
. 
. 
</LinearLayout> 
</android.support.v7.widget.CardView> 

ViewHolderは次のようなものに変更されます。

class MyViewHolder2 extends RecyclerView.ViewHolder { 

    RecyclerView recyclerView; 
    MyHorizontalAdapter horizontalAdapter; 
......//rest of objects 
..... 

    public MyViewHolder2(View itemView) { 
     super(itemView); 
     recyclerView = (RecyclerView) itemView.findViewById(R.id.recyclerView); 
     recyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)); 
     horizontalAdapter = new MyHorizontalAdapter(context); 
     recyclerView.setAdapter(horizontalAdapter); 
     recyclerView.setNestedScrollingEnabled(false); 
     .....//rest of initialization codes 
     ..... 
     ..... 
    } 

    public void bind(JSONObject object) throws JSONException { 
     horizontalAdapter.setHorizontalData(object.getJSONArray("phone")); 
     ........//rest of bind data 
     ....... 
     ....... 

    } 

DONOTはライン

recyclerView.setNestedScrollingEnabled(false); 

これは、垂直スクロールを傍受する水平recyclerViewを禁止し忘れます。

Horizo​​ntalAdapterでは、通常のRecyclerViewアダプタと同じように使用します。イメージを読み込んでいるので、PicassoやGlideのようなライブラリを使うことができます。

funtion-

public void setHorizontalData(JSONArray data){ 
.... 
notifyDataSetChanged(); 
} 
+0

作業中ですが、私のArralist リスト、画像が正しく表示されません。 – rahul

+0

もう少し情報を追加して、正しく表示されないことがありますか? ? @rahul – Harshit

+0

ViewHolderの中に 'adapter'を置くことを考えてくれてありがとう。 –