How to implement a horizontal RecyclerView inside another vertical RecyclerView











up vote
1
down vote

favorite












I want to put a horizontal RecyclerView(InnerRecyclerView) inside another vertical RecyclerView(OuterRecyclerView) and parse data into it after two separate volley calls. I was able to successfully parse the data to the vertical RecyclerView after the first webservice call. Now I'm trying to put the data from the second webservice into the horizontal RecyclerView.



For this I have implemented two seperate RecyclerView adapter classes. What I don't understand is how to define the InnerRecyclerView in the OuterRecyclerView and make the whole thing work together by passing data from the second web service call like I did in the first. I'm a beginner with this, I appreciate your help.



MainActivity.java



public class MainActivity extends AppCompatActivity {

RequestQueue requestQueue ;
RequestQueue requestQueue2 ;

RecyclerView recyclerView;

RecyclerView.Adapter recyclerViewadapter;
List<OuterDataModel> DataAdapterClassList;
List<InnerOuterDataModel> InnerAdapterClassList;
LinearLayoutManager recyclerViewlayoutManager;
public String callIdForParse;
OuterDataModel GetOuterDataModel = new OuterDataModel();


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);


DataAdapterClassList = new ArrayList<>();


recyclerView = (RecyclerView) findViewById(R.id.recyclerView1);

recyclerViewlayoutManager = new LinearLayoutManager(this);

recyclerView.setLayoutManager(recyclerViewlayoutManager);

myurl = "http://pastebin.com/START";


OuterWebCall();

//Some actions then I call the second webservice

InnerWebCall();


}



public void OuterWebCall(){

String HTTP_SERVER_URL= String.format("http://pastebin.com/mySampleApi/student/%1$s",mStudentRoll);
JsonArrayRequest jsArrRequest = new JsonArrayRequest
(Request.Method.POST, HTTP_SERVER_URL, null, new Response.Listener<JSONArray>() {

@Override
public void onResponse(JSONArray response) {
//mTxtDisplay.setText("Response: " + response.toString());

AfterOuterWebCall(response);
Log.i(TAG, "Hello");
}
}, new Response.ErrorListener() {

@Override
public void onErrorResponse(VolleyError error) {
// TODO Auto-generated method stub
}
}){

};
requestQueue = Volley.newRequestQueue(this);
requestQueue.add(jsArrRequest);
}



public void AfterOuterWebCall(JSONArray array){

for(int i = 0; i<array.length(); i++) {
OuterDataModel GetOuterDataModel = new OuterDataModel();
JSONObject json = null;
try {
json = array.getJSONObject(i);
GetOuterDataModel.setId(json.getString("CLASS"));
GetOuterDataModel.setPlateNo(json.getString("HOUSE"));
GetOuterDataModel.setPlateCode(json.getString("IMAGEURL"));

} catch (JSONException e) {
e.printStackTrace();
}
DataAdapterClassList.add(GetOuterDataModel);
mSwipeRefreshLayout.setRefreshing(false);
}
if (array.length() != 0) {
recyclerViewadapter = new NewRecyclerViewAdapter(DataAdapterClassList, this);
recyclerView.setAdapter(recyclerViewadapter);
}
}

public void InnerWebCall(){

String HTTP_SERVER_URL= String.format("http://192.1.2.2/test");

JsonArrayRequest jsArrRequest = new JsonArrayRequest
(Request.Method.POST, HTTP_SERVER_URL, null, new Response.Listener<JSONArray>() {

@Override
public void onResponse(JSONArray response) {
//mTxtDisplay.setText("Response: " + response.toString());

AfterInnerWebCall(response);
Log.i(TAG, "Hello");
}
}, new Response.ErrorListener() {

@Override
public void onErrorResponse(VolleyError error) {
// TODO Auto-generated method stub

}
}){

};


requestQueue2 = Volley.newRequestQueue(this);

requestQueue2.add(jsArrRequest);


}



public void AfterInnerWebCall (JSONArray array){

for(int i = 0; i<array.length(); i++) {

InnerOuterDataModel GetInnerOuterDataModel = new InnerOuterDataModel();

JSONObject json = null;
try {
json = array.getJSONObject(i);

GetInnerOuterDataModel.setName(json.getString("Name"));

GetInnerOuterDataModel.setRank(json.getString("Rank"));

GetInnerOuterDataModel.setPerId(json.getString("ID"));


} catch (JSONException e) {

e.printStackTrace();
}

InnerAdapterClassList.add(GetInnerOuterDataModel);


}
if (array.length() != 0) {

// How to pass the data to the InnerRecyclerViewAdapter?

}
}

}


OuterRecyclerViewAdapter.java



public class OuterRecyclerViewAdapter extends RecyclerView.Adapter<OuterRecyclerViewAdapter.ViewHolder> {

Context context;

public List<DataModel> dataModels;

public List<PersonnelOnDutyDataModel> dataModels2;

public int mExpandedPosition=-1;


public OuterRecyclerViewAdapter(List<DataModel> getDataAdapter, Context context){

super();
this.dataModels = getDataAdapter;
this.context = context;
}


@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_layout, parent, false);

ViewHolder viewHolder = new ViewHolder(view);

return viewHolder;

}


@Override
public void onBindViewHolder(final ViewHolder viewHolder, final int position) {

DataModel dataAdapter = dataModels.get(position);

RecyclerView.LayoutManager manager = new LinearLayoutManager(context);

viewHolder.InnerRecyclerView.setLayoutManager(manager);

viewHolder.class.setText(dataAdapter.getClass());

viewHolder.house.setText(dataAdapter.getHouse());

//Glide.with(context).load(dataAdapter.getImgUrl()).into(viewHolder.imageView)



final boolean isExpanded = position==mExpandedPosition;
// viewHolder.linearLayout.setVisibility(isExpanded?View.VISIBLE:View.GONE);
viewHolder.itemView.setActivated(isExpanded);
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mExpandedPosition = isExpanded ? -1:position;
//TransitionManager.beginDelayedTransition();
notifyDataSetChanged();
}
});


}


@Override
public int getItemCount() {

return dataModels.size();
}



class ViewHolder extends RecyclerView.ViewHolder{

public TextView class;
public TextView house;
public ImageView imageView;
private RecyclerView InnerRecyclerView;
ConstraintLayout constraintLayout;



public ViewHolder(View itemView) {

super(itemView);

InnerRecyclerView= (RecyclerView) itemView.findViewById(R.id.innerRecyclerView);

imageView = (ImageView) itemView.findViewById(R.id.imageView);
class=(TextView)itemView.findViewById(R.id.textViewClass);
house=(TextView)itemView.findViewById(R.id.textViewHouse);
constraintLayout=(ConstraintLayout)itemView.findViewById(R.id.constrainLayout);

}
}
}


InnerRecyclerView.java



public class InnerRecyclerViewAdapter extends RecyclerView.Adapter<InnerRecyclerViewAdapter.ViewHolder> {

Context context;

public List<InnerDataModel> dataModels;

public InnerRecyclerViewAdapter(List<InnerDataModel> getDataAdapter, Context context){

super();

this.dataModels = getDataAdapter;
this.context = context;
}

public int mExpandedPosition=-1;

@Override
public InnerRecyclerViewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.personnel_on_duty_card, parent, false);

InnerRecyclerViewAdapter.ViewHolder viewHolder = new InnerRecyclerViewAdapter.ViewHolder(view);

return viewHolder;


}

@Override
public void onBindViewHolder(final InnerRecyclerViewAdapter.ViewHolder viewHolder, final int position) {

InnerDataModel dataAdapter = dataModels.get(position);

viewHolder.NameStudentCard.setText(dataAdapter.getName());

viewHolder.RankCard.setText(dataAdapter.getRank());

viewHolder.IDCard.setText(dataAdapter.getId());

final boolean isExpanded = position==mExpandedPosition;

viewHolder.itemView.setActivated(isExpanded);
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mExpandedPosition = isExpanded ? -1:position;
//TransitionManager.beginDelayedTransition();
notifyDataSetChanged();
}
});

}


@Override
public int getItemCount() {

return dataModels.size();
}


class ViewHolder extends RecyclerView.ViewHolder{

public TextView NameStudentCard;
public TextView RankCard;
public TextView IDCard;
ConstraintLayout constraintLayout;


public ViewHolder(View itemView) {
super(itemView);
NameStudentCard=(TextView)itemView.findViewById(R.id.textViewNameInCard);
RankCard=(TextView)itemView.findViewById(R.id.textViewrankInCard);
IDCard =(TextView)itemView.findViewById(R.id.IDInCard);
constraintLayout=(ConstraintLayout)itemView.findViewById(R.id.constrainLayout);

}
}

}


MainActivity.xml



   <?xml version="1.0" encoding="utf-8"?>
<com.sothree.slidinguppanel.SlidingUpPanelLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:sothree="http://schemas.android.com/apk/res-auto"
android:id="@+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
sothree:umanoPanelHeight="68dp"
sothree:umanoShadowHeight="4dp"
sothree:umanoParallaxOffset="100dp"
sothree:umanoOverlay="true"
sothree:umanoFadeColor="@android:color/transparent">

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|top"
android:text=" Sliding Up Panel"
android:textSize="16sp" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical"
android:clickable="true"
android:focusable="false"
android:id="@+id/dragView">



<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>

</LinearLayout>

</com.sothree.slidinguppanel.SlidingUpPanelLayout>


OuterRecyclerView.xml



    <?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools"
android:id="@+id/CardViewOuter"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="4dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="4dp"
card_view:cardCornerRadius="4dp"
android:foreground="?attr/selectableItemBackground"
app:cardElevation="2dp"
android:transitionName="weatherCardTransition"
>

<android.support.constraint.ConstraintLayout
android:id="@+id/constrainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="@+id/textViewStatus"
app:layout_constraintTop_toBottomOf="@+id/textViewStatus">

<TextView
android:id="@+id/textViewClass"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:text="Class"
android:textColor="@color/card_text_primary"
android:textSize="36sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />


<TextView
android:id="@+id/textViewHose"
android:layout_width="wrap_content"
android:layout_height="28dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/card_header_status"
android:textSize="18sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textViewCalass" />

<android.support.v7.widget.RecyclerView
android:layout_width="352dp"
android:layout_height="134dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:id="@+id/innerRecyclerView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textViewCalass" />


</android.support.constraint.ConstraintLayout>


</android.support.v7.widget.CardView>


InnerCard.xml



<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools"
android:id="@+id/cardViewInnerCard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="4dp"
card_view:cardCornerRadius="4dp"
android:foreground="?attr/selectableItemBackground"
app:cardElevation="2dp"
android:transitionName="weatherCardTransition"
>


<android.support.constraint.ConstraintLayout
android:layout_width="200dp"
android:layout_height="100dp">

<TextView
android:id="@+id/textViewNameInCard"
android:layout_width="wrap_content"
android:layout_height="19dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/textViewrankInCard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textViewNameInCard" />

<TextView
android:id="@+id/IDInCard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textViewrankInCard" />

<ImageButton
android:id="@+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:background="@null"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="@drawable/ic_more_vert_black_24dp" />
</android.support.constraint.ConstraintLayout>











share|improve this question




















  • 1




    Can you post your item xml of both?
    – Ümañg ßürmån
    Nov 8 at 8:17






  • 1




    @New Coder by analogy, is the very same problem of a matrix, which you would represent in any language as an array of array ... so instead of having mDataset, you will have mDataset ... the first iteration over it (you outer recycler view) will give you the rows, each of which is mDataset, which you will pass over, and then you'll have the second iteration over each row (your inner recycler view) that will give you each item data set to bind to the view, per each row
    – Alessio
    Nov 8 at 8:23












  • @Alessio could you please explain it to me in my code?
    – New Coder
    Nov 8 at 8:29










  • @Ümañgßürmån xml files are added
    – New Coder
    Nov 8 at 8:31






  • 1




    Initialise your inner adapter in the onBindViewHolder of the outer adapter, the same way you initialised the outer adapter in the activity.
    – Cool Guy CG
    Nov 8 at 8:47















up vote
1
down vote

favorite












I want to put a horizontal RecyclerView(InnerRecyclerView) inside another vertical RecyclerView(OuterRecyclerView) and parse data into it after two separate volley calls. I was able to successfully parse the data to the vertical RecyclerView after the first webservice call. Now I'm trying to put the data from the second webservice into the horizontal RecyclerView.



For this I have implemented two seperate RecyclerView adapter classes. What I don't understand is how to define the InnerRecyclerView in the OuterRecyclerView and make the whole thing work together by passing data from the second web service call like I did in the first. I'm a beginner with this, I appreciate your help.



MainActivity.java



public class MainActivity extends AppCompatActivity {

RequestQueue requestQueue ;
RequestQueue requestQueue2 ;

RecyclerView recyclerView;

RecyclerView.Adapter recyclerViewadapter;
List<OuterDataModel> DataAdapterClassList;
List<InnerOuterDataModel> InnerAdapterClassList;
LinearLayoutManager recyclerViewlayoutManager;
public String callIdForParse;
OuterDataModel GetOuterDataModel = new OuterDataModel();


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);


DataAdapterClassList = new ArrayList<>();


recyclerView = (RecyclerView) findViewById(R.id.recyclerView1);

recyclerViewlayoutManager = new LinearLayoutManager(this);

recyclerView.setLayoutManager(recyclerViewlayoutManager);

myurl = "http://pastebin.com/START";


OuterWebCall();

//Some actions then I call the second webservice

InnerWebCall();


}



public void OuterWebCall(){

String HTTP_SERVER_URL= String.format("http://pastebin.com/mySampleApi/student/%1$s",mStudentRoll);
JsonArrayRequest jsArrRequest = new JsonArrayRequest
(Request.Method.POST, HTTP_SERVER_URL, null, new Response.Listener<JSONArray>() {

@Override
public void onResponse(JSONArray response) {
//mTxtDisplay.setText("Response: " + response.toString());

AfterOuterWebCall(response);
Log.i(TAG, "Hello");
}
}, new Response.ErrorListener() {

@Override
public void onErrorResponse(VolleyError error) {
// TODO Auto-generated method stub
}
}){

};
requestQueue = Volley.newRequestQueue(this);
requestQueue.add(jsArrRequest);
}



public void AfterOuterWebCall(JSONArray array){

for(int i = 0; i<array.length(); i++) {
OuterDataModel GetOuterDataModel = new OuterDataModel();
JSONObject json = null;
try {
json = array.getJSONObject(i);
GetOuterDataModel.setId(json.getString("CLASS"));
GetOuterDataModel.setPlateNo(json.getString("HOUSE"));
GetOuterDataModel.setPlateCode(json.getString("IMAGEURL"));

} catch (JSONException e) {
e.printStackTrace();
}
DataAdapterClassList.add(GetOuterDataModel);
mSwipeRefreshLayout.setRefreshing(false);
}
if (array.length() != 0) {
recyclerViewadapter = new NewRecyclerViewAdapter(DataAdapterClassList, this);
recyclerView.setAdapter(recyclerViewadapter);
}
}

public void InnerWebCall(){

String HTTP_SERVER_URL= String.format("http://192.1.2.2/test");

JsonArrayRequest jsArrRequest = new JsonArrayRequest
(Request.Method.POST, HTTP_SERVER_URL, null, new Response.Listener<JSONArray>() {

@Override
public void onResponse(JSONArray response) {
//mTxtDisplay.setText("Response: " + response.toString());

AfterInnerWebCall(response);
Log.i(TAG, "Hello");
}
}, new Response.ErrorListener() {

@Override
public void onErrorResponse(VolleyError error) {
// TODO Auto-generated method stub

}
}){

};


requestQueue2 = Volley.newRequestQueue(this);

requestQueue2.add(jsArrRequest);


}



public void AfterInnerWebCall (JSONArray array){

for(int i = 0; i<array.length(); i++) {

InnerOuterDataModel GetInnerOuterDataModel = new InnerOuterDataModel();

JSONObject json = null;
try {
json = array.getJSONObject(i);

GetInnerOuterDataModel.setName(json.getString("Name"));

GetInnerOuterDataModel.setRank(json.getString("Rank"));

GetInnerOuterDataModel.setPerId(json.getString("ID"));


} catch (JSONException e) {

e.printStackTrace();
}

InnerAdapterClassList.add(GetInnerOuterDataModel);


}
if (array.length() != 0) {

// How to pass the data to the InnerRecyclerViewAdapter?

}
}

}


OuterRecyclerViewAdapter.java



public class OuterRecyclerViewAdapter extends RecyclerView.Adapter<OuterRecyclerViewAdapter.ViewHolder> {

Context context;

public List<DataModel> dataModels;

public List<PersonnelOnDutyDataModel> dataModels2;

public int mExpandedPosition=-1;


public OuterRecyclerViewAdapter(List<DataModel> getDataAdapter, Context context){

super();
this.dataModels = getDataAdapter;
this.context = context;
}


@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_layout, parent, false);

ViewHolder viewHolder = new ViewHolder(view);

return viewHolder;

}


@Override
public void onBindViewHolder(final ViewHolder viewHolder, final int position) {

DataModel dataAdapter = dataModels.get(position);

RecyclerView.LayoutManager manager = new LinearLayoutManager(context);

viewHolder.InnerRecyclerView.setLayoutManager(manager);

viewHolder.class.setText(dataAdapter.getClass());

viewHolder.house.setText(dataAdapter.getHouse());

//Glide.with(context).load(dataAdapter.getImgUrl()).into(viewHolder.imageView)



final boolean isExpanded = position==mExpandedPosition;
// viewHolder.linearLayout.setVisibility(isExpanded?View.VISIBLE:View.GONE);
viewHolder.itemView.setActivated(isExpanded);
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mExpandedPosition = isExpanded ? -1:position;
//TransitionManager.beginDelayedTransition();
notifyDataSetChanged();
}
});


}


@Override
public int getItemCount() {

return dataModels.size();
}



class ViewHolder extends RecyclerView.ViewHolder{

public TextView class;
public TextView house;
public ImageView imageView;
private RecyclerView InnerRecyclerView;
ConstraintLayout constraintLayout;



public ViewHolder(View itemView) {

super(itemView);

InnerRecyclerView= (RecyclerView) itemView.findViewById(R.id.innerRecyclerView);

imageView = (ImageView) itemView.findViewById(R.id.imageView);
class=(TextView)itemView.findViewById(R.id.textViewClass);
house=(TextView)itemView.findViewById(R.id.textViewHouse);
constraintLayout=(ConstraintLayout)itemView.findViewById(R.id.constrainLayout);

}
}
}


InnerRecyclerView.java



public class InnerRecyclerViewAdapter extends RecyclerView.Adapter<InnerRecyclerViewAdapter.ViewHolder> {

Context context;

public List<InnerDataModel> dataModels;

public InnerRecyclerViewAdapter(List<InnerDataModel> getDataAdapter, Context context){

super();

this.dataModels = getDataAdapter;
this.context = context;
}

public int mExpandedPosition=-1;

@Override
public InnerRecyclerViewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.personnel_on_duty_card, parent, false);

InnerRecyclerViewAdapter.ViewHolder viewHolder = new InnerRecyclerViewAdapter.ViewHolder(view);

return viewHolder;


}

@Override
public void onBindViewHolder(final InnerRecyclerViewAdapter.ViewHolder viewHolder, final int position) {

InnerDataModel dataAdapter = dataModels.get(position);

viewHolder.NameStudentCard.setText(dataAdapter.getName());

viewHolder.RankCard.setText(dataAdapter.getRank());

viewHolder.IDCard.setText(dataAdapter.getId());

final boolean isExpanded = position==mExpandedPosition;

viewHolder.itemView.setActivated(isExpanded);
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mExpandedPosition = isExpanded ? -1:position;
//TransitionManager.beginDelayedTransition();
notifyDataSetChanged();
}
});

}


@Override
public int getItemCount() {

return dataModels.size();
}


class ViewHolder extends RecyclerView.ViewHolder{

public TextView NameStudentCard;
public TextView RankCard;
public TextView IDCard;
ConstraintLayout constraintLayout;


public ViewHolder(View itemView) {
super(itemView);
NameStudentCard=(TextView)itemView.findViewById(R.id.textViewNameInCard);
RankCard=(TextView)itemView.findViewById(R.id.textViewrankInCard);
IDCard =(TextView)itemView.findViewById(R.id.IDInCard);
constraintLayout=(ConstraintLayout)itemView.findViewById(R.id.constrainLayout);

}
}

}


MainActivity.xml



   <?xml version="1.0" encoding="utf-8"?>
<com.sothree.slidinguppanel.SlidingUpPanelLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:sothree="http://schemas.android.com/apk/res-auto"
android:id="@+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
sothree:umanoPanelHeight="68dp"
sothree:umanoShadowHeight="4dp"
sothree:umanoParallaxOffset="100dp"
sothree:umanoOverlay="true"
sothree:umanoFadeColor="@android:color/transparent">

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|top"
android:text=" Sliding Up Panel"
android:textSize="16sp" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical"
android:clickable="true"
android:focusable="false"
android:id="@+id/dragView">



<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>

</LinearLayout>

</com.sothree.slidinguppanel.SlidingUpPanelLayout>


OuterRecyclerView.xml



    <?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools"
android:id="@+id/CardViewOuter"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="4dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="4dp"
card_view:cardCornerRadius="4dp"
android:foreground="?attr/selectableItemBackground"
app:cardElevation="2dp"
android:transitionName="weatherCardTransition"
>

<android.support.constraint.ConstraintLayout
android:id="@+id/constrainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="@+id/textViewStatus"
app:layout_constraintTop_toBottomOf="@+id/textViewStatus">

<TextView
android:id="@+id/textViewClass"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:text="Class"
android:textColor="@color/card_text_primary"
android:textSize="36sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />


<TextView
android:id="@+id/textViewHose"
android:layout_width="wrap_content"
android:layout_height="28dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/card_header_status"
android:textSize="18sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textViewCalass" />

<android.support.v7.widget.RecyclerView
android:layout_width="352dp"
android:layout_height="134dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:id="@+id/innerRecyclerView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textViewCalass" />


</android.support.constraint.ConstraintLayout>


</android.support.v7.widget.CardView>


InnerCard.xml



<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools"
android:id="@+id/cardViewInnerCard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="4dp"
card_view:cardCornerRadius="4dp"
android:foreground="?attr/selectableItemBackground"
app:cardElevation="2dp"
android:transitionName="weatherCardTransition"
>


<android.support.constraint.ConstraintLayout
android:layout_width="200dp"
android:layout_height="100dp">

<TextView
android:id="@+id/textViewNameInCard"
android:layout_width="wrap_content"
android:layout_height="19dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/textViewrankInCard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textViewNameInCard" />

<TextView
android:id="@+id/IDInCard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textViewrankInCard" />

<ImageButton
android:id="@+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:background="@null"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="@drawable/ic_more_vert_black_24dp" />
</android.support.constraint.ConstraintLayout>











share|improve this question




















  • 1




    Can you post your item xml of both?
    – Ümañg ßürmån
    Nov 8 at 8:17






  • 1




    @New Coder by analogy, is the very same problem of a matrix, which you would represent in any language as an array of array ... so instead of having mDataset, you will have mDataset ... the first iteration over it (you outer recycler view) will give you the rows, each of which is mDataset, which you will pass over, and then you'll have the second iteration over each row (your inner recycler view) that will give you each item data set to bind to the view, per each row
    – Alessio
    Nov 8 at 8:23












  • @Alessio could you please explain it to me in my code?
    – New Coder
    Nov 8 at 8:29










  • @Ümañgßürmån xml files are added
    – New Coder
    Nov 8 at 8:31






  • 1




    Initialise your inner adapter in the onBindViewHolder of the outer adapter, the same way you initialised the outer adapter in the activity.
    – Cool Guy CG
    Nov 8 at 8:47













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I want to put a horizontal RecyclerView(InnerRecyclerView) inside another vertical RecyclerView(OuterRecyclerView) and parse data into it after two separate volley calls. I was able to successfully parse the data to the vertical RecyclerView after the first webservice call. Now I'm trying to put the data from the second webservice into the horizontal RecyclerView.



For this I have implemented two seperate RecyclerView adapter classes. What I don't understand is how to define the InnerRecyclerView in the OuterRecyclerView and make the whole thing work together by passing data from the second web service call like I did in the first. I'm a beginner with this, I appreciate your help.



MainActivity.java



public class MainActivity extends AppCompatActivity {

RequestQueue requestQueue ;
RequestQueue requestQueue2 ;

RecyclerView recyclerView;

RecyclerView.Adapter recyclerViewadapter;
List<OuterDataModel> DataAdapterClassList;
List<InnerOuterDataModel> InnerAdapterClassList;
LinearLayoutManager recyclerViewlayoutManager;
public String callIdForParse;
OuterDataModel GetOuterDataModel = new OuterDataModel();


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);


DataAdapterClassList = new ArrayList<>();


recyclerView = (RecyclerView) findViewById(R.id.recyclerView1);

recyclerViewlayoutManager = new LinearLayoutManager(this);

recyclerView.setLayoutManager(recyclerViewlayoutManager);

myurl = "http://pastebin.com/START";


OuterWebCall();

//Some actions then I call the second webservice

InnerWebCall();


}



public void OuterWebCall(){

String HTTP_SERVER_URL= String.format("http://pastebin.com/mySampleApi/student/%1$s",mStudentRoll);
JsonArrayRequest jsArrRequest = new JsonArrayRequest
(Request.Method.POST, HTTP_SERVER_URL, null, new Response.Listener<JSONArray>() {

@Override
public void onResponse(JSONArray response) {
//mTxtDisplay.setText("Response: " + response.toString());

AfterOuterWebCall(response);
Log.i(TAG, "Hello");
}
}, new Response.ErrorListener() {

@Override
public void onErrorResponse(VolleyError error) {
// TODO Auto-generated method stub
}
}){

};
requestQueue = Volley.newRequestQueue(this);
requestQueue.add(jsArrRequest);
}



public void AfterOuterWebCall(JSONArray array){

for(int i = 0; i<array.length(); i++) {
OuterDataModel GetOuterDataModel = new OuterDataModel();
JSONObject json = null;
try {
json = array.getJSONObject(i);
GetOuterDataModel.setId(json.getString("CLASS"));
GetOuterDataModel.setPlateNo(json.getString("HOUSE"));
GetOuterDataModel.setPlateCode(json.getString("IMAGEURL"));

} catch (JSONException e) {
e.printStackTrace();
}
DataAdapterClassList.add(GetOuterDataModel);
mSwipeRefreshLayout.setRefreshing(false);
}
if (array.length() != 0) {
recyclerViewadapter = new NewRecyclerViewAdapter(DataAdapterClassList, this);
recyclerView.setAdapter(recyclerViewadapter);
}
}

public void InnerWebCall(){

String HTTP_SERVER_URL= String.format("http://192.1.2.2/test");

JsonArrayRequest jsArrRequest = new JsonArrayRequest
(Request.Method.POST, HTTP_SERVER_URL, null, new Response.Listener<JSONArray>() {

@Override
public void onResponse(JSONArray response) {
//mTxtDisplay.setText("Response: " + response.toString());

AfterInnerWebCall(response);
Log.i(TAG, "Hello");
}
}, new Response.ErrorListener() {

@Override
public void onErrorResponse(VolleyError error) {
// TODO Auto-generated method stub

}
}){

};


requestQueue2 = Volley.newRequestQueue(this);

requestQueue2.add(jsArrRequest);


}



public void AfterInnerWebCall (JSONArray array){

for(int i = 0; i<array.length(); i++) {

InnerOuterDataModel GetInnerOuterDataModel = new InnerOuterDataModel();

JSONObject json = null;
try {
json = array.getJSONObject(i);

GetInnerOuterDataModel.setName(json.getString("Name"));

GetInnerOuterDataModel.setRank(json.getString("Rank"));

GetInnerOuterDataModel.setPerId(json.getString("ID"));


} catch (JSONException e) {

e.printStackTrace();
}

InnerAdapterClassList.add(GetInnerOuterDataModel);


}
if (array.length() != 0) {

// How to pass the data to the InnerRecyclerViewAdapter?

}
}

}


OuterRecyclerViewAdapter.java



public class OuterRecyclerViewAdapter extends RecyclerView.Adapter<OuterRecyclerViewAdapter.ViewHolder> {

Context context;

public List<DataModel> dataModels;

public List<PersonnelOnDutyDataModel> dataModels2;

public int mExpandedPosition=-1;


public OuterRecyclerViewAdapter(List<DataModel> getDataAdapter, Context context){

super();
this.dataModels = getDataAdapter;
this.context = context;
}


@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_layout, parent, false);

ViewHolder viewHolder = new ViewHolder(view);

return viewHolder;

}


@Override
public void onBindViewHolder(final ViewHolder viewHolder, final int position) {

DataModel dataAdapter = dataModels.get(position);

RecyclerView.LayoutManager manager = new LinearLayoutManager(context);

viewHolder.InnerRecyclerView.setLayoutManager(manager);

viewHolder.class.setText(dataAdapter.getClass());

viewHolder.house.setText(dataAdapter.getHouse());

//Glide.with(context).load(dataAdapter.getImgUrl()).into(viewHolder.imageView)



final boolean isExpanded = position==mExpandedPosition;
// viewHolder.linearLayout.setVisibility(isExpanded?View.VISIBLE:View.GONE);
viewHolder.itemView.setActivated(isExpanded);
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mExpandedPosition = isExpanded ? -1:position;
//TransitionManager.beginDelayedTransition();
notifyDataSetChanged();
}
});


}


@Override
public int getItemCount() {

return dataModels.size();
}



class ViewHolder extends RecyclerView.ViewHolder{

public TextView class;
public TextView house;
public ImageView imageView;
private RecyclerView InnerRecyclerView;
ConstraintLayout constraintLayout;



public ViewHolder(View itemView) {

super(itemView);

InnerRecyclerView= (RecyclerView) itemView.findViewById(R.id.innerRecyclerView);

imageView = (ImageView) itemView.findViewById(R.id.imageView);
class=(TextView)itemView.findViewById(R.id.textViewClass);
house=(TextView)itemView.findViewById(R.id.textViewHouse);
constraintLayout=(ConstraintLayout)itemView.findViewById(R.id.constrainLayout);

}
}
}


InnerRecyclerView.java



public class InnerRecyclerViewAdapter extends RecyclerView.Adapter<InnerRecyclerViewAdapter.ViewHolder> {

Context context;

public List<InnerDataModel> dataModels;

public InnerRecyclerViewAdapter(List<InnerDataModel> getDataAdapter, Context context){

super();

this.dataModels = getDataAdapter;
this.context = context;
}

public int mExpandedPosition=-1;

@Override
public InnerRecyclerViewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.personnel_on_duty_card, parent, false);

InnerRecyclerViewAdapter.ViewHolder viewHolder = new InnerRecyclerViewAdapter.ViewHolder(view);

return viewHolder;


}

@Override
public void onBindViewHolder(final InnerRecyclerViewAdapter.ViewHolder viewHolder, final int position) {

InnerDataModel dataAdapter = dataModels.get(position);

viewHolder.NameStudentCard.setText(dataAdapter.getName());

viewHolder.RankCard.setText(dataAdapter.getRank());

viewHolder.IDCard.setText(dataAdapter.getId());

final boolean isExpanded = position==mExpandedPosition;

viewHolder.itemView.setActivated(isExpanded);
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mExpandedPosition = isExpanded ? -1:position;
//TransitionManager.beginDelayedTransition();
notifyDataSetChanged();
}
});

}


@Override
public int getItemCount() {

return dataModels.size();
}


class ViewHolder extends RecyclerView.ViewHolder{

public TextView NameStudentCard;
public TextView RankCard;
public TextView IDCard;
ConstraintLayout constraintLayout;


public ViewHolder(View itemView) {
super(itemView);
NameStudentCard=(TextView)itemView.findViewById(R.id.textViewNameInCard);
RankCard=(TextView)itemView.findViewById(R.id.textViewrankInCard);
IDCard =(TextView)itemView.findViewById(R.id.IDInCard);
constraintLayout=(ConstraintLayout)itemView.findViewById(R.id.constrainLayout);

}
}

}


MainActivity.xml



   <?xml version="1.0" encoding="utf-8"?>
<com.sothree.slidinguppanel.SlidingUpPanelLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:sothree="http://schemas.android.com/apk/res-auto"
android:id="@+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
sothree:umanoPanelHeight="68dp"
sothree:umanoShadowHeight="4dp"
sothree:umanoParallaxOffset="100dp"
sothree:umanoOverlay="true"
sothree:umanoFadeColor="@android:color/transparent">

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|top"
android:text=" Sliding Up Panel"
android:textSize="16sp" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical"
android:clickable="true"
android:focusable="false"
android:id="@+id/dragView">



<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>

</LinearLayout>

</com.sothree.slidinguppanel.SlidingUpPanelLayout>


OuterRecyclerView.xml



    <?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools"
android:id="@+id/CardViewOuter"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="4dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="4dp"
card_view:cardCornerRadius="4dp"
android:foreground="?attr/selectableItemBackground"
app:cardElevation="2dp"
android:transitionName="weatherCardTransition"
>

<android.support.constraint.ConstraintLayout
android:id="@+id/constrainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="@+id/textViewStatus"
app:layout_constraintTop_toBottomOf="@+id/textViewStatus">

<TextView
android:id="@+id/textViewClass"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:text="Class"
android:textColor="@color/card_text_primary"
android:textSize="36sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />


<TextView
android:id="@+id/textViewHose"
android:layout_width="wrap_content"
android:layout_height="28dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/card_header_status"
android:textSize="18sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textViewCalass" />

<android.support.v7.widget.RecyclerView
android:layout_width="352dp"
android:layout_height="134dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:id="@+id/innerRecyclerView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textViewCalass" />


</android.support.constraint.ConstraintLayout>


</android.support.v7.widget.CardView>


InnerCard.xml



<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools"
android:id="@+id/cardViewInnerCard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="4dp"
card_view:cardCornerRadius="4dp"
android:foreground="?attr/selectableItemBackground"
app:cardElevation="2dp"
android:transitionName="weatherCardTransition"
>


<android.support.constraint.ConstraintLayout
android:layout_width="200dp"
android:layout_height="100dp">

<TextView
android:id="@+id/textViewNameInCard"
android:layout_width="wrap_content"
android:layout_height="19dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/textViewrankInCard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textViewNameInCard" />

<TextView
android:id="@+id/IDInCard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textViewrankInCard" />

<ImageButton
android:id="@+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:background="@null"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="@drawable/ic_more_vert_black_24dp" />
</android.support.constraint.ConstraintLayout>











share|improve this question















I want to put a horizontal RecyclerView(InnerRecyclerView) inside another vertical RecyclerView(OuterRecyclerView) and parse data into it after two separate volley calls. I was able to successfully parse the data to the vertical RecyclerView after the first webservice call. Now I'm trying to put the data from the second webservice into the horizontal RecyclerView.



For this I have implemented two seperate RecyclerView adapter classes. What I don't understand is how to define the InnerRecyclerView in the OuterRecyclerView and make the whole thing work together by passing data from the second web service call like I did in the first. I'm a beginner with this, I appreciate your help.



MainActivity.java



public class MainActivity extends AppCompatActivity {

RequestQueue requestQueue ;
RequestQueue requestQueue2 ;

RecyclerView recyclerView;

RecyclerView.Adapter recyclerViewadapter;
List<OuterDataModel> DataAdapterClassList;
List<InnerOuterDataModel> InnerAdapterClassList;
LinearLayoutManager recyclerViewlayoutManager;
public String callIdForParse;
OuterDataModel GetOuterDataModel = new OuterDataModel();


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);


DataAdapterClassList = new ArrayList<>();


recyclerView = (RecyclerView) findViewById(R.id.recyclerView1);

recyclerViewlayoutManager = new LinearLayoutManager(this);

recyclerView.setLayoutManager(recyclerViewlayoutManager);

myurl = "http://pastebin.com/START";


OuterWebCall();

//Some actions then I call the second webservice

InnerWebCall();


}



public void OuterWebCall(){

String HTTP_SERVER_URL= String.format("http://pastebin.com/mySampleApi/student/%1$s",mStudentRoll);
JsonArrayRequest jsArrRequest = new JsonArrayRequest
(Request.Method.POST, HTTP_SERVER_URL, null, new Response.Listener<JSONArray>() {

@Override
public void onResponse(JSONArray response) {
//mTxtDisplay.setText("Response: " + response.toString());

AfterOuterWebCall(response);
Log.i(TAG, "Hello");
}
}, new Response.ErrorListener() {

@Override
public void onErrorResponse(VolleyError error) {
// TODO Auto-generated method stub
}
}){

};
requestQueue = Volley.newRequestQueue(this);
requestQueue.add(jsArrRequest);
}



public void AfterOuterWebCall(JSONArray array){

for(int i = 0; i<array.length(); i++) {
OuterDataModel GetOuterDataModel = new OuterDataModel();
JSONObject json = null;
try {
json = array.getJSONObject(i);
GetOuterDataModel.setId(json.getString("CLASS"));
GetOuterDataModel.setPlateNo(json.getString("HOUSE"));
GetOuterDataModel.setPlateCode(json.getString("IMAGEURL"));

} catch (JSONException e) {
e.printStackTrace();
}
DataAdapterClassList.add(GetOuterDataModel);
mSwipeRefreshLayout.setRefreshing(false);
}
if (array.length() != 0) {
recyclerViewadapter = new NewRecyclerViewAdapter(DataAdapterClassList, this);
recyclerView.setAdapter(recyclerViewadapter);
}
}

public void InnerWebCall(){

String HTTP_SERVER_URL= String.format("http://192.1.2.2/test");

JsonArrayRequest jsArrRequest = new JsonArrayRequest
(Request.Method.POST, HTTP_SERVER_URL, null, new Response.Listener<JSONArray>() {

@Override
public void onResponse(JSONArray response) {
//mTxtDisplay.setText("Response: " + response.toString());

AfterInnerWebCall(response);
Log.i(TAG, "Hello");
}
}, new Response.ErrorListener() {

@Override
public void onErrorResponse(VolleyError error) {
// TODO Auto-generated method stub

}
}){

};


requestQueue2 = Volley.newRequestQueue(this);

requestQueue2.add(jsArrRequest);


}



public void AfterInnerWebCall (JSONArray array){

for(int i = 0; i<array.length(); i++) {

InnerOuterDataModel GetInnerOuterDataModel = new InnerOuterDataModel();

JSONObject json = null;
try {
json = array.getJSONObject(i);

GetInnerOuterDataModel.setName(json.getString("Name"));

GetInnerOuterDataModel.setRank(json.getString("Rank"));

GetInnerOuterDataModel.setPerId(json.getString("ID"));


} catch (JSONException e) {

e.printStackTrace();
}

InnerAdapterClassList.add(GetInnerOuterDataModel);


}
if (array.length() != 0) {

// How to pass the data to the InnerRecyclerViewAdapter?

}
}

}


OuterRecyclerViewAdapter.java



public class OuterRecyclerViewAdapter extends RecyclerView.Adapter<OuterRecyclerViewAdapter.ViewHolder> {

Context context;

public List<DataModel> dataModels;

public List<PersonnelOnDutyDataModel> dataModels2;

public int mExpandedPosition=-1;


public OuterRecyclerViewAdapter(List<DataModel> getDataAdapter, Context context){

super();
this.dataModels = getDataAdapter;
this.context = context;
}


@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_layout, parent, false);

ViewHolder viewHolder = new ViewHolder(view);

return viewHolder;

}


@Override
public void onBindViewHolder(final ViewHolder viewHolder, final int position) {

DataModel dataAdapter = dataModels.get(position);

RecyclerView.LayoutManager manager = new LinearLayoutManager(context);

viewHolder.InnerRecyclerView.setLayoutManager(manager);

viewHolder.class.setText(dataAdapter.getClass());

viewHolder.house.setText(dataAdapter.getHouse());

//Glide.with(context).load(dataAdapter.getImgUrl()).into(viewHolder.imageView)



final boolean isExpanded = position==mExpandedPosition;
// viewHolder.linearLayout.setVisibility(isExpanded?View.VISIBLE:View.GONE);
viewHolder.itemView.setActivated(isExpanded);
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mExpandedPosition = isExpanded ? -1:position;
//TransitionManager.beginDelayedTransition();
notifyDataSetChanged();
}
});


}


@Override
public int getItemCount() {

return dataModels.size();
}



class ViewHolder extends RecyclerView.ViewHolder{

public TextView class;
public TextView house;
public ImageView imageView;
private RecyclerView InnerRecyclerView;
ConstraintLayout constraintLayout;



public ViewHolder(View itemView) {

super(itemView);

InnerRecyclerView= (RecyclerView) itemView.findViewById(R.id.innerRecyclerView);

imageView = (ImageView) itemView.findViewById(R.id.imageView);
class=(TextView)itemView.findViewById(R.id.textViewClass);
house=(TextView)itemView.findViewById(R.id.textViewHouse);
constraintLayout=(ConstraintLayout)itemView.findViewById(R.id.constrainLayout);

}
}
}


InnerRecyclerView.java



public class InnerRecyclerViewAdapter extends RecyclerView.Adapter<InnerRecyclerViewAdapter.ViewHolder> {

Context context;

public List<InnerDataModel> dataModels;

public InnerRecyclerViewAdapter(List<InnerDataModel> getDataAdapter, Context context){

super();

this.dataModels = getDataAdapter;
this.context = context;
}

public int mExpandedPosition=-1;

@Override
public InnerRecyclerViewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.personnel_on_duty_card, parent, false);

InnerRecyclerViewAdapter.ViewHolder viewHolder = new InnerRecyclerViewAdapter.ViewHolder(view);

return viewHolder;


}

@Override
public void onBindViewHolder(final InnerRecyclerViewAdapter.ViewHolder viewHolder, final int position) {

InnerDataModel dataAdapter = dataModels.get(position);

viewHolder.NameStudentCard.setText(dataAdapter.getName());

viewHolder.RankCard.setText(dataAdapter.getRank());

viewHolder.IDCard.setText(dataAdapter.getId());

final boolean isExpanded = position==mExpandedPosition;

viewHolder.itemView.setActivated(isExpanded);
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mExpandedPosition = isExpanded ? -1:position;
//TransitionManager.beginDelayedTransition();
notifyDataSetChanged();
}
});

}


@Override
public int getItemCount() {

return dataModels.size();
}


class ViewHolder extends RecyclerView.ViewHolder{

public TextView NameStudentCard;
public TextView RankCard;
public TextView IDCard;
ConstraintLayout constraintLayout;


public ViewHolder(View itemView) {
super(itemView);
NameStudentCard=(TextView)itemView.findViewById(R.id.textViewNameInCard);
RankCard=(TextView)itemView.findViewById(R.id.textViewrankInCard);
IDCard =(TextView)itemView.findViewById(R.id.IDInCard);
constraintLayout=(ConstraintLayout)itemView.findViewById(R.id.constrainLayout);

}
}

}


MainActivity.xml



   <?xml version="1.0" encoding="utf-8"?>
<com.sothree.slidinguppanel.SlidingUpPanelLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:sothree="http://schemas.android.com/apk/res-auto"
android:id="@+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
sothree:umanoPanelHeight="68dp"
sothree:umanoShadowHeight="4dp"
sothree:umanoParallaxOffset="100dp"
sothree:umanoOverlay="true"
sothree:umanoFadeColor="@android:color/transparent">

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|top"
android:text=" Sliding Up Panel"
android:textSize="16sp" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical"
android:clickable="true"
android:focusable="false"
android:id="@+id/dragView">



<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>

</LinearLayout>

</com.sothree.slidinguppanel.SlidingUpPanelLayout>


OuterRecyclerView.xml



    <?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools"
android:id="@+id/CardViewOuter"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="4dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="4dp"
card_view:cardCornerRadius="4dp"
android:foreground="?attr/selectableItemBackground"
app:cardElevation="2dp"
android:transitionName="weatherCardTransition"
>

<android.support.constraint.ConstraintLayout
android:id="@+id/constrainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="@+id/textViewStatus"
app:layout_constraintTop_toBottomOf="@+id/textViewStatus">

<TextView
android:id="@+id/textViewClass"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:text="Class"
android:textColor="@color/card_text_primary"
android:textSize="36sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />


<TextView
android:id="@+id/textViewHose"
android:layout_width="wrap_content"
android:layout_height="28dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/card_header_status"
android:textSize="18sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textViewCalass" />

<android.support.v7.widget.RecyclerView
android:layout_width="352dp"
android:layout_height="134dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:id="@+id/innerRecyclerView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textViewCalass" />


</android.support.constraint.ConstraintLayout>


</android.support.v7.widget.CardView>


InnerCard.xml



<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools"
android:id="@+id/cardViewInnerCard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="4dp"
card_view:cardCornerRadius="4dp"
android:foreground="?attr/selectableItemBackground"
app:cardElevation="2dp"
android:transitionName="weatherCardTransition"
>


<android.support.constraint.ConstraintLayout
android:layout_width="200dp"
android:layout_height="100dp">

<TextView
android:id="@+id/textViewNameInCard"
android:layout_width="wrap_content"
android:layout_height="19dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/textViewrankInCard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textViewNameInCard" />

<TextView
android:id="@+id/IDInCard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textViewrankInCard" />

<ImageButton
android:id="@+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:background="@null"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="@drawable/ic_more_vert_black_24dp" />
</android.support.constraint.ConstraintLayout>








java android android-recyclerview






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 8 at 8:28

























asked Nov 8 at 8:13









New Coder

4110




4110








  • 1




    Can you post your item xml of both?
    – Ümañg ßürmån
    Nov 8 at 8:17






  • 1




    @New Coder by analogy, is the very same problem of a matrix, which you would represent in any language as an array of array ... so instead of having mDataset, you will have mDataset ... the first iteration over it (you outer recycler view) will give you the rows, each of which is mDataset, which you will pass over, and then you'll have the second iteration over each row (your inner recycler view) that will give you each item data set to bind to the view, per each row
    – Alessio
    Nov 8 at 8:23












  • @Alessio could you please explain it to me in my code?
    – New Coder
    Nov 8 at 8:29










  • @Ümañgßürmån xml files are added
    – New Coder
    Nov 8 at 8:31






  • 1




    Initialise your inner adapter in the onBindViewHolder of the outer adapter, the same way you initialised the outer adapter in the activity.
    – Cool Guy CG
    Nov 8 at 8:47














  • 1




    Can you post your item xml of both?
    – Ümañg ßürmån
    Nov 8 at 8:17






  • 1




    @New Coder by analogy, is the very same problem of a matrix, which you would represent in any language as an array of array ... so instead of having mDataset, you will have mDataset ... the first iteration over it (you outer recycler view) will give you the rows, each of which is mDataset, which you will pass over, and then you'll have the second iteration over each row (your inner recycler view) that will give you each item data set to bind to the view, per each row
    – Alessio
    Nov 8 at 8:23












  • @Alessio could you please explain it to me in my code?
    – New Coder
    Nov 8 at 8:29










  • @Ümañgßürmån xml files are added
    – New Coder
    Nov 8 at 8:31






  • 1




    Initialise your inner adapter in the onBindViewHolder of the outer adapter, the same way you initialised the outer adapter in the activity.
    – Cool Guy CG
    Nov 8 at 8:47








1




1




Can you post your item xml of both?
– Ümañg ßürmån
Nov 8 at 8:17




Can you post your item xml of both?
– Ümañg ßürmån
Nov 8 at 8:17




1




1




@New Coder by analogy, is the very same problem of a matrix, which you would represent in any language as an array of array ... so instead of having mDataset, you will have mDataset ... the first iteration over it (you outer recycler view) will give you the rows, each of which is mDataset, which you will pass over, and then you'll have the second iteration over each row (your inner recycler view) that will give you each item data set to bind to the view, per each row
– Alessio
Nov 8 at 8:23






@New Coder by analogy, is the very same problem of a matrix, which you would represent in any language as an array of array ... so instead of having mDataset, you will have mDataset ... the first iteration over it (you outer recycler view) will give you the rows, each of which is mDataset, which you will pass over, and then you'll have the second iteration over each row (your inner recycler view) that will give you each item data set to bind to the view, per each row
– Alessio
Nov 8 at 8:23














@Alessio could you please explain it to me in my code?
– New Coder
Nov 8 at 8:29




@Alessio could you please explain it to me in my code?
– New Coder
Nov 8 at 8:29












@Ümañgßürmån xml files are added
– New Coder
Nov 8 at 8:31




@Ümañgßürmån xml files are added
– New Coder
Nov 8 at 8:31




1




1




Initialise your inner adapter in the onBindViewHolder of the outer adapter, the same way you initialised the outer adapter in the activity.
– Cool Guy CG
Nov 8 at 8:47




Initialise your inner adapter in the onBindViewHolder of the outer adapter, the same way you initialised the outer adapter in the activity.
– Cool Guy CG
Nov 8 at 8:47

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53203692%2fhow-to-implement-a-horizontal-recyclerview-inside-another-vertical-recyclerview%23new-answer', 'question_page');
}
);

Post as a guest





































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53203692%2fhow-to-implement-a-horizontal-recyclerview-inside-another-vertical-recyclerview%23new-answer', 'question_page');
}
);

Post as a guest




















































































Popular posts from this blog

Schultheiß

Verwaltungsgliederung Dänemarks

Liste der Kulturdenkmale in Wilsdruff