2016-06-09 91 views
11

我剛看完Advanced Data Binding - Google I/O 2016,並希望應用以下內容來減少我在不同視圖中使用的表達式的重複次數。無法引用Android數據綁定中的其他視圖ID

enter image description here

但我不能讓它在我的情況下工作:

<ImageButton 
       android:id="@+id/btn_list" 
       android:layout_width="48dp" 
       android:layout_height="48dp" 
       android:layout_gravity="start" 
       android:background="@drawable/btn_s01_list" 
       android:visibility="@{bean.shouldHideControls? View.GONE: View.VISIBLE}"/> 

      <ToggleButton 
       android:id="@+id/btn_radar" 
       android:layout_width="48dp" 
       android:layout_height="48dp" 
       android:background="@drawable/btn_radar_selector" 
       android:checked="false" 
       android:gravity="end" 
       android:text="" 
       android:textOff="" 
       android:textOn="" 
       android:visibility="@{btn_list.visibility}"/> 

和我

Error:(426, 39) Identifiers must have user defined types from the XML file. btn_list is missing it

編輯:

我錯過了一個重要點同樣的談話...查看ID被駱駝化了。

enter image description here

回答

16

的結合過程中你的ID轉換爲屬性的綁定類,而生成的名字是駱駝casified。

您可能需要更改以下行:

android:visibility="@{btn_list.visibility}"/> 

要這樣:

android:visibility="@{btnList.visibility}"/>