後,我的gradle AS版本升級到2.3.0, 數據綁定遭遇警告:數據綁定 - safeUnbox警告
警告:SelectMAP編程[指數]是一個盒裝的領域,但需要取消裝箱爲執行selectMap [index]? @android:顏色/白色:@android:顏色/透明。這可能會導致NPE,因此數據綁定將安全地解除它。你可以改變的表達,並明確包裹SelectMAP編程[指數]與safeUnbox(),以防止警告
SelectMAP編程是一個ObservableMap,然後我搜索這個警告,但僅獲得少量的討論,並沒有解決它
Android Studio 2.3.0-alpha1: Databinding + int unboxing causes compile errors
Databinding - data object is null on API 15-18
我遵循的聯繫方式,修改selectMap[index]
到safeUnbox(selectMap[index])
但有語法錯誤。
那麼有誰知道如何解決這個警告?
編輯: 下面是XML文件中的代碼
<?xml version="1.0" encoding="utf-8"?>
<data class="SupportCountryViewHolderBinding">
<variable
name="viewModel"
type="com.goodarc.care_about.activity.account.support_country.SupportCountryHolderViewModel" />
<variable
name="dataSource"
type="com.goodarc.care_about.module.assets_file.SupportCountry" />
<variable
name="selectMap"
type="android.databinding.ObservableMap<Integer, Boolean>" />
<variable
name="index"
type="int" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@{selectMap[index] ? @android:color/white : @android:color/transparent}"
android:onClick="@{(v) -> viewModel.onItemSelectListener(selectMap, index)}"
android:orientation="vertical"
android:padding="20dp">
<TextView
style="@style/TitleLabel2"
android:layout_gravity="center_vertical|start"
android:text="@{dataSource.display}"
android:textColor="@{selectMap[index] ? @android:color/black : @android:color/white}"
tools:text="Taiwan (+886)" />
</LinearLayout>
構建是成功的,但警告出來(我過去的上方)。
哪裏是你的問題的代碼? – pskink