0
https://developer.android.com/topic/libraries/data-binding/index.html:Android的数据在Android 4.1的结合不起作用
数据绑定库提供了灵活性和广泛的 兼容性 - 这是一个支持库,这样你就可以与所有 Android平台版本使用回到Android 2.1(API等级7+)。
但是,当我试图在我的项目中使用数据绑定它不工作,没有任何反应,TextViews是空的,onClick绑定只是不workx,请帮助我,我需要支持为Android 4.1,谷歌就知道应该甚至2.1是可能的,我不认为他们在撒谎:/
示例代码:
<FrameLayout
android:layout_width="130dp"
android:layout_height="0dp"
android:layout_weight="15"
android:layout_gravity="center"
android:background="@color/colorSecondary"
android:clickable="true"
android:onClick="@{() -> view.save() }" <!-- binding -->
android:layout_margin="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/save"
android:textAllCaps="true"
android:textColor="@color/colorForeground"/>
</FrameLayout>
后面的代码:
public void save()
{
if(viewModel.car.save() != 0) //If you put breakpoint here it won't be hit
getLayoutRoot().goBack();
}
代码工作在API级别的微小19+
是它与其他API级别的工作? –
请发布您迄今尝试过的代码。 –
是的,完全在19+ API级别上工作得很好。 – QTM