title: androidx.recyclerview.widget.RecyclerView$LayoutParams cannot be cast to androidx.constraintlayout.widget.ConstraintLayout$LayoutParams
body: <p>I have an Activity which xml layout contains Constraint layout and Linearlayout, RecyclerView as it's child layouts.</p>
  
  <p>I have a button tied to an onCLick listener on the adapter, every time a click is performed. The application crashes and logs this error.</p>
  
  <pre><code>2019-09-11 09:52:19.713 22060-22060/com.myapp E/AndroidRuntime: FATAL EXCEPTION: main
      Process: com.myapp PID: 22060
      java.lang.ClassCastException: androidx.recyclerview.widget.RecyclerView$LayoutParams cannot be cast to androidx.constraintlayout.widget.ConstraintLayout$LayoutParams
          at androidx.constraintlayout.widget.ConstraintLayout.getTargetWidget(ConstraintLayout.java:1144)
          at androidx.constraintlayout.widget.ConstraintLayout.setChildrenConstraints(ConstraintLayout.java:1028)
          at androidx.constraintlayout.widget.ConstraintLayout.updateHierarchy(ConstraintLayout.java:803)
          at androidx.constraintlayout.widget.ConstraintLayout.onMeasure(ConstraintLayout.java:1561)
          at android.view.View.measure(View.java:22071)
          at androidx.constraintlayout.widget.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1227)
          at androidx.constraintlayout.widget.ConstraintLayout.onMeasure(ConstraintLayout.java:1572)
          at android.view.View.measure(View.java:22071)
          at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
          at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
          at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143)
          at android.view.View.measure(View.java:22071)
          at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
          at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
          at android.widget.LinearLayout.measureVertical(LinearLayout.java:806)
          at android.widget.LinearLayout.onMeasure(LinearLayout.java:685)
          at android.view.View.measure(View.java:22071)
          at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
          at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
          at android.view.View.measure(View.java:22071)
          at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
          at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
          at android.widget.LinearLayout.measureVertical(LinearLayout.java:806)
          at android.widget.LinearLayout.onMeasure(LinearLayout.java:685)
          at android.view.View.measure(View.java:22071)
          at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
          at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
          at com.android.internal.policy.DecorView.onMeasure(DecorView.java:724)
          at android.view.View.measure(View.java:22071)
          at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2422)
          at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1504)
          at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1761)
          at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1392)
          at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6752)
          at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
          at android.view.Choreographer.doCallbacks(Choreographer.java:723)
          at android.view.Choreographer.doFrame(Choreographer.java:658)
          at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
          at android.os.Handler.handleCallback(Handler.java:790)
          at android.os.Handler.dispatchMessage(Handler.java:99)
          at android.os.Looper.loop(Looper.java:164)
          at android.app.ActivityThread.main(ActivityThread.java:6494)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
  </code></pre>
  
  <p>This is my activity layout below:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;androidx.constraintlayout.widget.ConstraintLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_margin="8dp"
      android:elevation="2dp"
      android:background="@drawable/bill_border"
      tools:context=".ui.MyBillsActivity"&gt;
  
          &lt;androidx.constraintlayout.widget.ConstraintLayout
              android:id="@+id/container"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:layout_gravity="center"
              android:paddingBottom="60dp"
              app:layout_constraintLeft_toLeftOf="parent"
              app:layout_constraintRight_toRightOf="parent"
              app:layout_constraintTop_toBottomOf="parent"&gt;
  
                  &lt;androidx.appcompat.widget.AppCompatTextView
                      android:id="@+id/number_of_parts"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:text="@string/parts"
                      android:textColor="@color/colorPrimary"
                      android:gravity="center"
                      android:padding="20dp"
                      app:layout_constraintLeft_toLeftOf="parent"
                      app:layout_constraintRight_toRightOf="parent" /&gt;
  
                  &lt;LinearLayout
                      android:id="@+id/parts_button"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:gravity="center"
                      app:layout_constraintLeft_toLeftOf="parent"
                      app:layout_constraintRight_toRightOf="parent"
                      app:layout_constraintTop_toBottomOf="@id/number_of_parts"&gt;
  
                          &lt;androidx.appcompat.widget.AppCompatButton
                              android:layout_width="35dp"
                              android:layout_height="35dp"
                              android:text="2"
                              android:gravity="center"
                              android:textColor="@color/colorPrimary"
                              android:paddingTop="4dp"
                              android:paddingRight="1dp"
                              android:paddingBottom="4dp"
                              android:paddingLeft="1dp"
                              android:layout_marginStart="10dp"
                              android:background="@drawable/send_bill_selector_background" /&gt;
  
                          &lt;androidx.appcompat.widget.AppCompatButton
                              android:layout_width="35dp"
                              android:layout_height="35dp"
                              android:text="3"
                              android:textColor="@color/colorPrimary"
                              android:paddingTop="4dp"
                              android:paddingRight="1dp"
                              android:paddingBottom="4dp"
                              android:paddingLeft="1dp"
                              android:layout_marginStart="10dp"
                              android:background="@drawable/send_bill_selector_background" /&gt;
  
                          &lt;androidx.appcompat.widget.AppCompatButton
                              android:layout_width="35dp"
                              android:layout_height="35dp"
                              android:text="4"
                              android:textColor="@color/colorPrimary"
                              android:paddingTop="4dp"
                              android:paddingRight="1dp"
                              android:paddingBottom="4dp"
                              android:paddingLeft="1dp"
                              android:layout_marginStart="10dp"
                              android:background="@drawable/send_bill_selector_background" /&gt;
  
                          &lt;androidx.appcompat.widget.AppCompatButton
                              android:layout_width="35dp"
                              android:layout_height="35dp"
                              android:text="5"
                              android:textColor="@color/colorPrimary"
                              android:paddingTop="4dp"
                              android:paddingRight="1dp"
                              android:paddingBottom="4dp"
                              android:paddingLeft="1dp"
                              android:layout_marginStart="10dp"
                              android:background="@drawable/send_bill_selector_background" /&gt;
  
                  &lt;/LinearLayout&gt;
  
                  &lt;TextView
                      android:id="@+id/date_and_amount"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:text="@string/number_of_parts"
                      android:textColor="@color/colorPrimary"
                      android:gravity="center"
                      android:layout_marginTop="40dp"
                      app:layout_constraintLeft_toLeftOf="parent"
                      app:layout_constraintRight_toRightOf="parent"
                      app:layout_constraintTop_toBottomOf="@id/parts_button" /&gt;
  
  
                  &lt;LinearLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:gravity="center"
                      app:layout_constraintLeft_toLeftOf="parent"
                      app:layout_constraintRight_toRightOf="parent"
                      app:layout_constraintTop_toBottomOf="@id/date_and_amount"&gt;
  
                          &lt;!-- send bill recycler list --&gt;
                          &lt;androidx.recyclerview.widget.RecyclerView
                              android:id="@+id/recycler"
                              android:layout_width="match_parent"
                              android:layout_height="wrap_content"
                              app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"/&gt;
  
                  &lt;/LinearLayout&gt;
  
  
                  &lt;androidx.appcompat.widget.AppCompatTextView
                      android:id="@+id/tap_text"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_centerHorizontal="true"
                      android:drawableLeft="@drawable/error_outline"
                      android:drawablePadding="4dp"
                      android:text="This is a special text"
                      android:textColor="@color/colorPrimary"
                      android:textSize="13sp"
                      android:gravity="center"
                      android:paddingTop="4dp"
                      android:paddingRight="4dp"
                      android:paddingBottom="4dp"
                      android:paddingLeft="4dp"
                      app:layout_constraintLeft_toLeftOf="parent"
                      app:layout_constraintRight_toRightOf="parent"
                      app:layout_constraintTop_toBottomOf="@id/payment_layout"/&gt;
  
          &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  
  
          &lt;FrameLayout
              android:layout_width="0dp"
              android:layout_height="wrap_content"
              android:layout_marginBottom="20dp"
              app:layout_constraintBottom_toBottomOf="parent"
              app:layout_constraintEnd_toEndOf="parent"
              app:layout_constraintStart_toStartOf="parent"&gt;
  
  
                  &lt;Button
                      android:id="@+id/send_button"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_centerInParent="true"
                      android:layout_gravity="center"
                      app:text="Submit Button"/&gt;
  
          &lt;/FrameLayout&gt;
  
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  </code></pre>
  
  <p>This is my ADAPTER class below: </p>
  
  <pre><code>public class MysBillAdapter extends RecyclerView.Adapter&lt;MysBillAdapter.MyBillViewHolder&gt; {
  
      private String[] mDataset;
  
      public static class MyBillViewHolder extends RecyclerView.ViewHolder {
  
          private final AppCompatButton hideShow;
          private final LinearLayout percentageLayout;
          private final LinearLayout dueDateLayout;
  
          public View view;
  
          public MyBillViewHolder(View v) {
              super(v);
              hideShow = v.findViewById(R.id.hide_show);
              percentageLayout = v.findViewById(R.id.percentage_layout);
              dueDateLayout = v.findViewById(R.id.due_date_layout);
          }
      }
  
      // Provide a suitable constructor (depends on the kind of dataset)
      public MysBillAdapter(String[] myDataset) {
          mDataset = myDataset;
      }
  
      // Create new views (invoked by the layout manager)
      @Override
      public MysBillAdapter.MyBillViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
          // create a new view
          View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_bills, parent, false);
          return new MyBillViewHolder(v);
      }
  
      // Replace the contents of a view (invoked by the layout manager)
      @Override
      public void onBindViewHolder(@NonNull final MyBillViewHolder holder, final int position) {
  
          holder.hideShow.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  holder.percentageLayout.setVisibility(View.GONE); // This throws an exception
              }
          });
  
      }
  
      // Return the size of your dataset (invoked by the layout manager)
      @Override
      public int getItemCount() {
          return mDataset.length;
      }
  }
  </code></pre>
  
  <p>My layout_bills xml</p>
  
  <pre><code>&lt;LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/my_payment_layout"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:background="@drawable/bill_border"
      android:orientation="horizontal"
      android:elevation="2dp"
      android:layout_marginTop="10dp"
      android:layout_marginLeft="30dp"
      android:layout_marginRight="30dp"
      android:layout_marginBottom="5dp"
      android:padding="10dp"&gt;
  
      &lt;!-- payment --&gt;
      &lt;LinearLayout
          android:id="@+id/box1"
          android:layout_width="230dp"
          android:layout_height="wrap_content"
          android:layout_marginStart="0dp"
          android:layout_marginTop="4dp"
          android:background="@drawable/border"
          android:orientation="vertical"&gt;
  
  
          &lt;!-- percentage form --&gt;
          &lt;LinearLayout
              android:id="@+id/percentage_layout"
              android:orientation="horizontal"
              android:layout_marginTop="20dp"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"&gt;
  
              &lt;androidx.appcompat.widget.AppCompatEditText
                  android:layout_width="65dp"
                  android:layout_height="35dp"
                  android:text="3"
                  android:textSize="13sp"
                  android:inputType="number"
                  android:maxLength="3"
                  android:textColor="@color/colorPrimaryDark"
                  android:gravity="center"
                  android:paddingTop="4dp"
                  android:paddingRight="1dp"
                  android:paddingBottom="4dp"
                  android:paddingLeft="1dp"
                  android:background="@drawable/border_dark_blue" /&gt;
  
              &lt;androidx.appcompat.widget.AppCompatTextView
                  android:layout_width="25dp"
                  android:layout_height="35dp"
                  android:text="%"
                  android:textColor="@color/colorPrimaryDark"
                  android:gravity="center"
                  android:paddingTop="4dp"
                  android:paddingRight="1dp"
                  android:paddingBottom="4dp"
                  android:paddingLeft="1dp"
                  /&gt;
  
              &lt;androidx.appcompat.widget.AppCompatTextView
                  android:layout_width="65dp"
                  android:layout_height="35dp"
                  android:text="of 100"
                  android:textColor="@color/colorPrimaryDark"
                  android:gravity="left"
                  android:paddingTop="4dp"
                  android:paddingRight="1dp"
                  android:paddingBottom="4dp"
                  android:paddingLeft="1dp"
                  /&gt;
  
          &lt;/LinearLayout&gt;
  
  
          &lt;!-- percentage form --&gt;
          &lt;LinearLayout
              android:id="@+id/due_date_layout"
              android:orientation="horizontal"
              android:layout_marginTop="15dp"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:background="@drawable/border_dark_blue"&gt;
  
              &lt;androidx.appcompat.widget.AppCompatImageView
                  android:layout_width="45dp"
                  android:layout_height="wrap_content"
                  android:src="@drawable/my_calender"
                  android:gravity="center"
                  android:layout_marginTop="3dp"
                  android:paddingTop="4dp"
                  android:paddingRight="1dp"
                  android:paddingBottom="4dp"
                  android:paddingLeft="1dp" /&gt;
  
              &lt;androidx.appcompat.widget.AppCompatTextView
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:text="My payment Due Date"
                  android:textColor="@color/colorPrimaryDark"
                  android:gravity="center"
                  android:layout_marginTop="3dp"
                  android:paddingTop="4dp"
                  android:paddingRight="1dp"
                  android:paddingBottom="4dp"
                  android:paddingLeft="1dp" /&gt;
  
              &lt;androidx.appcompat.widget.AppCompatImageView
                  android:layout_width="45dp"
                  android:layout_height="35dp"
                  android:src="@drawable/arrow_right"
                  android:gravity="left"
                  android:paddingTop="4dp"
                  android:paddingRight="1dp"
                  android:paddingBottom="4dp"
                  android:paddingLeft="1dp" /&gt;
  
          &lt;/LinearLayout&gt;
  
      &lt;/LinearLayout&gt;
  
  
  
      &lt;!-- edit --&gt;
      &lt;LinearLayout
          android:id="@+id/box3"
          android:layout_width="wrap_content"
          android:layout_height="match_parent"
          android:layout_marginStart="0dp"
          android:layout_marginTop="0dp"
          android:gravity="center"&gt;
  
          &lt;androidx.appcompat.widget.AppCompatButton
              android:id="@+id/hide_show"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:textColor="@color/colorPrimary"
              android:background="@color/white"
              android:gravity="center"
              android:tag="hide"
              android:text="HIDE" /&gt;
  
      &lt;/LinearLayout&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>My Activity class</p>
  
  <pre><code>public class MyBillActivity extends AppCompatActivity {
  
      private RecyclerView recyclerView;
      private RecyclerView.Adapter mAdapter;
      private RecyclerView.LayoutManager layoutManager;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_my_bill);
  
  
  
          recyclerView = (RecyclerView) findViewById(R.id.recycler);
          recyclerView.setHasFixedSize(true);
  
          layoutManager = new LinearLayoutManager(this);
          recyclerView.setLayoutManager(layoutManager);
  
  
          // specify an adapter (see also next example)
          mAdapter = new MyBillAdapter(new String[]{"", "", "", ""});
          recyclerView.setAdapter(mAdapter);
  
      }
  
  }
  </code></pre>