Mus*_*eel 16 android android-databinding
我一直试图使用android数据绑定中的隐式属性监听器(引用)来控制视图的可见性,它允许通过id和访问属性(如checked,visible等)访问视图,但是当尝试使用它时,它会抛出像这样的错误
Error:(119, 29) Identifiers must have user defined types from the XML file. addTodo_switch_remind is missing it
Run Code Online (Sandbox Code Playgroud)
<android.support.v7.widget.SwitchCompat
android:id="@+id/addTodo_switch_remind"
style="@style/MediumTextViewStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/addTodo_space_project"
android:text="@string/add_todo_remind_label"
android:textOff="@string/generic_no_text"
android:textOn="@string/generic_yes_text" />
<android.support.v4.widget.Space
android:id="@+id/addTodo_space_remind"
style="@style/FormsSpacingStyle"
android:layout_below="@+id/addTodo_switch_remind" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/addTodo_space_remind"
android:orientation="vertical"
android:padding="@dimen/grid_box_single"
android:visibility="@{addTodo_switch_remind.checked ? View.VISIBLE : View.GONE}">
Run Code Online (Sandbox Code Playgroud)
Xia*_*ang 50
在.xml文件中使用View.VISIBLE/ View.GONE时,应View通过<import type="android.view.View"/>在data部分中进行添加来导入类型,如下所示:
<data>
<import type="android.view.View"/>
<variable
name="viewModel"
type="xx.xx.MyViewModel"/>
</data>
Run Code Online (Sandbox Code Playgroud)
Mus*_*eel 23
看起来隐式属性侦听器在表达式中使用驼峰的情况下,感谢这篇文章我想出来了.
<!--Recurring Reminder -->
<android.support.v7.widget.SwitchCompat
android:id="@+id/addTodo_switch_remind"
style="@style/MediumTextViewStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/addTodo_space_project"
android:text="@string/add_todo_remind_label"
android:textOff="@string/generic_no_text"
android:textOn="@string/generic_yes_text" />
<android.support.v4.widget.Space
android:id="@+id/addTodo_space_remind"
style="@style/FormsSpacingStyle"
android:layout_below="@+id/addTodo_switch_remind" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/addTodo_space_remind"
android:orientation="vertical"
android:padding="@dimen/grid_box_single"
android:visibility="@{addTodoSwitchRemind.checked ? View.VISIBLE : View.GONE}">
Run Code Online (Sandbox Code Playgroud)
记录具有相同问题的其他人