title: Custom Android view has wrong type when inflating from XML
body: <p>I have a custom view, that extends <code>LinearLayout</code>:</p>
  <pre class="lang-kotlin prettyprint-override"><code>class MyCustomView @JvmOverloads constructor(
      context: Context,
      attrs: AttributeSet? = null
  ) : LinearLayout(context, attrs) {
  
      private val binding = MyCustomViewBinding.inflate(LayoutInflater.from(context), this, true)
      
      // ...
  }
  </code></pre>
  <p>And I need to define a custom wrapper (similar to <a href="https://developer.android.com/reference/com/google/android/material/textfield/TextInputLayout" rel="nofollow noreferrer">TextInputLayout</a>), that can include a child <code>MyCustomView</code> object and has a special logic to inflate it.  So I want to be able to define the views in XML as follows:</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;com.example.MyCustomWrapper 
           android:layout_width=&quot;match_parent&quot;
           android:layout_height=&quot;wrap_content&quot;&gt;
  
       &lt;com.example.MyCustomView
               android:layout_width=&quot;match_parent&quot;
               android:layout_height=&quot;wrap_content&quot;/&gt;
  
   &lt;/com.example.MyCustomWrapper&gt;
  </code></pre>
  <p>For that purpose I override <code>addView()</code> method (similar to <a href="https://android.googlesource.com/platform/frameworks/support/+/81fdc55/design/src/android/support/design/widget/TextInputLayout.java#140" rel="nofollow noreferrer">https://android.googlesource.com/platform/frameworks/support/+/81fdc55/design/src/android/support/design/widget/TextInputLayout.java#140</a> ), that is called during XML inflation:</p>
  <pre class="lang-kotlin prettyprint-override"><code>class MyCustomWrapper @JvmOverloads constructor(
      context: Context,
      attrs: AttributeSet? = null
  ) : ConstraintLayout(context, attrs) {
  
      private val binding = MyCustomWrapper Binding.inflate(LayoutInflater.from(context), this, true)
      
      override fun addView(child: View?) {
          if (child is MyCustomView) {
              // custom logic
          } else {
              super.addView(child)
          }
      }
  }
  </code></pre>
  <p>Unfortunately, it doesn't work: the condition <code>child is MyCustomView</code> is always false, in debugger child is only typed as <code>LinearLayout</code>. Any ideas, how to fix this?</p>