0

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!

1 Answers1

0

Try this my friend

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">


    <RelativeLayout
        android:id="@+id/linearLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="10dp"
            android:text="@string/app_name"
            android:textAppearance="@style/TextAppearance.AppCompat.Tooltip" />
    </RelativeLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="10dp">
    </android.support.v7.widget.RecyclerView>


</LinearLayout>
Ratilal Chopda
  • 4,162
  • 4
  • 18
  • 31