Hilt 数据绑定:一个特定视图正在获取“无法找到标识符”
我有一个可以使用 Hilt 的应用程序。添加了下面的布局,但这个特定的 spinner
视图存在问题,而其余部分工作正常。微调器数据绑定本身正在工作并且正在填充条目,但由于某种原因,这部分无法找到视图 ID tags_spinner
。
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:onClick="@{(view) -> viewModel.process(tags_spinner)}"/>
不寻常的是,另一个图像按钮可以很好地找到其目标视图。
`<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:onClick="@{(view) -> viewModel.process(tag)}"/>`
我的应用程序在这些版本上运行:
hilt_version = '2.40.5'
lifecycle_version = '2.4.1'
kapt_version = '1.6.20-RC'
下面的布局代码。
<layout 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">
<data>
<variable
name="viewModel"
type="com.base.BaseActivityViewModel" />
<variable
name="adapter"
type="android.widget.ArrayAdapter" />
<import type="android.view.View"/>
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/trackerNameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Page Name"
android:text="@={viewModel.page.pageName}"
app:layout_constraintTop_toTopOf="parent"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/trackerNameEditText">
<Spinner
android:id="@+id/tags_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:listitem="@android:layout/simple_spinner_dropdown_item"
android:setAdapter="@{adapter}"
android:entries="@{viewModel.tagsList}"/>
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:onClick="@{(view) -> viewModel.process(tags_spinner)}"/>
<EditText
android:id="@+id/tag"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:hint="New Tag"/>
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:onClick="@{(view) -> viewModel.process(tag)}"/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
I have a working app with Hilt. Added the layout below but this specific spinner
view is having problems while the rest is working fine. The spinner data binding itself is working and entries being populated, but for some reason this part cannot find the view id tags_spinner
.
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:onClick="@{(view) -> viewModel.process(tags_spinner)}"/>
The unusual thing is the other image button can find its target view just fine.
`<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:onClick="@{(view) -> viewModel.process(tag)}"/>`
My app is running on these versions:
hilt_version = '2.40.5'
lifecycle_version = '2.4.1'
kapt_version = '1.6.20-RC'
Layout code below.
<layout 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">
<data>
<variable
name="viewModel"
type="com.base.BaseActivityViewModel" />
<variable
name="adapter"
type="android.widget.ArrayAdapter" />
<import type="android.view.View"/>
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/trackerNameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Page Name"
android:text="@={viewModel.page.pageName}"
app:layout_constraintTop_toTopOf="parent"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/trackerNameEditText">
<Spinner
android:id="@+id/tags_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:listitem="@android:layout/simple_spinner_dropdown_item"
android:setAdapter="@{adapter}"
android:entries="@{viewModel.tagsList}"/>
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:onClick="@{(view) -> viewModel.process(tags_spinner)}"/>
<EditText
android:id="@+id/tag"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:hint="New Tag"/>
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:onClick="@{(view) -> viewModel.process(tag)}"/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发现这是一个我还没有完全理解的错误,它在分配包含未描述的
_
的视图 id 时导致问题。只需将我的分配更改为"@+id/tagsSpinner"
即可解决问题。Found that it is a bug which I haven't fully understood yet, it causes the problem when assigning view ids containing an undescrore
_
. Simply changing my assignment to"@+id/tagsSpinner"
fixed the problem.