Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android 3.6 ViewStubProxy Unresolved reference

I have this Kotlin code:

if(this.fragmentMeasurementBinding.viewStub.isInflated)
{
    return;
}
this.fragmentMeasurementBinding.viewStub.viewStub?.layoutResource =
      R.layout.layout_measurement_single_value
this.fragmentMeasurementBinding.viewStub.setOnInflateListener { _, inflated ->
      LayoutMeasurementSingleValueBinding.bind(inflated)?.let {
          it.textInputLayoutSingleMeasurementValue.hint = Helper.getDynamicStringResource(
            this.context, parent.getItemAtPosition(position).toString(), prefix = "title_")
      }
}
this.fragmentMeasurementBinding.viewStub.viewStub?.inflate() 

And this on my XML file:

<?xml version="1.0" encoding="utf-8"?>
<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"
    tools:context=".fragments.MeasurementFragment">

    <ViewStub
        android:id="@+id/viewStub"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/text_input_layout_measure" />

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/text_input_layout_measure"
        style="@style/AppTheme.Widget.TextInput.ExposedDropdownMenu"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:descendantFocusability="blocksDescendants"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <AutoCompleteTextView
            android:id="@+id/exposed_dropdown_measure"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/what_are_you_measure"
            android:imeOptions="actionNext"
            android:labelFor="@id/text_input_layout_measure" />
    </com.google.android.material.textfield.TextInputLayout>

</androidx.constraintlayout.widget.ConstraintLayout> 

When I compile the Android studio report the following errors:

  • Unresolved reference: isInflated
  • Unresolved reference: viewStub
  • Unresolved reference: viewStub

I am using the new ViewBinding from Google I am develop with Android Studio 3.6 Canary 12, Gradle 3.6.0-alpha12. This is a bug from Android Studio or my bug?

like image 256
rneves Avatar asked Oct 02 '19 08:10

rneves


1 Answers

I use ViewBinding everywhere, however, due to this issue with the ViewStubProxy Unresolved reference that I cannot find a solution either, in this particular case, I use the good friend findViewById.

For instance:

class MainActivity: AppCompatActivity{

    //...

    private val myView: View by lazy {
        findViewById<ViewStub>(R.id.my_view_stub).inflate()
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val binding = ActivityMainBinding.inflate(layoutInflater)
        //...
    }

    //...

    fun displayMyView() {
        myView.isVisible = true
        //
    }

}

Or if you require to work with the inner views of your inflated stub using the binding:

private val myViewBinding: MyViewBinding by lazy {
    MyViewBinding.bind(findViewById<ViewStub>(R.id.my_view_stub).inflate())
}
like image 99
RedDeath Avatar answered Oct 29 '22 18:10

RedDeath