我正在尝试通过 xml 将“@string”和“@stringarray”传递给我的视图数据绑定,但它不起作用。我收到以下错误消息:
C:\Users\censored\AndroidStudioProjects\example\app\build\generated\source\kapt\debug\com\example\app\databinding\AppStandardContactFormBindingImpl.java:943: error: cannot find symbol
if (this.appDefaultCompanyNameEt.isInflated()) this.appDefaultCompanyNameEt.getBinding().setVariable(BR.hint, appDefaultCompanyNameEt.getResources().getString(R.string.app_contact_form_company_name));
^
symbol: method getResources()
location: variable appDefaultCompanyNameEt of type ViewStubProxy
ViewStub 膨胀布局
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="vBility"
type="Boolean" />
<variable
name="vForm"
type="String" />
<variable
name="hint"
type="String" />
<variable
name="iType"
type="Integer" />
<variable
name="mText"
type="String" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="@{vBility}">
<com.example.app.presentation.util.view.FixedInputTextLayout
android:id="@+id/app_default_et"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="@dimen/wrapContent"
android:layout_height="wrap_content"
android:hint="@{hint}"
android:visibility="@{vBility}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:validate_form="@{vForm}">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="@{iType}"
android:text="@={mText}"
android:textSize="@dimen/font_text_large" />
</com.example.app.presentation.util.view.FixedInputTextLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
在viewstub中使用布局
<ViewStub
android:id="@+id/app_default_company_name_et"
android:layout_width="@dimen/wrapContent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:inflatedId="@+id/app_default_company_name_et"
android:layout="@layout/app_standard_textinputlayout"
android:visibility="@{cValidator.companySwitchState}"
app:vBility="@{cValidator.companySwitchState}"
app:vForm="@{cValidator.etCompanyNameEM}"
app:hint="@{@string/app_contact_form_company_name}" <!-- THIS IS GIVING ME THE ERROR -->
app:iType="@{0x00000001}"
app:mText="@{cValidator.etCompanyName}"
app:layout_constraintEnd_toStartOf="@+id/app_default_company_ust_et"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="@+id/margin_left"
app:layout_constraintTop_toBottomOf="@+id/calibrate_user_data_company_text" />
当我改变它app:hint="@{@string/app_contact_form_company_name}"
时app:hint="@{someClass.someString}"
。这是否意味着,如果它是一个视图,我不能直接将任何字符串传递给我的数据绑定?