I am trying to make my RecyclerView
to hold two different Layouts, e.g Card and a TextView
. I want my `TextView' to be at position 0 of the 'RecyclerView' and the rest positions binding to cards normally.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_below="@+id/linearLayout">
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
Next I show some of my adapter methods:
My onCreateViewHolder
:
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
Log.d(TAG,"viewType: " + viewType);
View view = inflater.inflate(R.layout.card_item, parent, false);
return new ViewHolder(view);
}
Next is onBindViewHolder
.
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
//position 0 tem o ViewHolder tem o Layout da TextView
if(position==0){
View view = inflater.inflate(R.layout.above_card_view, holder.getParent(), false);
//holder??
}else{
Pick data = picks.get(position);
Log.d(TAG, data.toString());
String aux = data.getCountry() + " - " + data.getLeague();
holder.getFlag().setImageResource(data.getFlag_src());
holder.getLeague().setText(aux);
}
}
Any idea how can I do it? Thanks!