2016-08-05 27 views
0

https://developer.android.com/topic/libraries/data-binding/index.htmlAndroid的数据在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+

+0

是它与其他API级别的工作? –

+1

请发布您迄今尝试过的代码。 –

+0

是的,完全在19+ API级别上工作得很好。 – QTM

回答

0

我发现这个问题,我在的prebind事件返回false时SDK_INT <奇巧在我的自动转换功能:

 binding.addOnRebindCallback(new OnRebindCallback() 
     { 
      @Override 
      public boolean onPreBind(ViewDataBinding binding) 
      { 
       if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) 
        return false; //should be true, that's it 

       ViewGroup sceneRoot = (ViewGroup) binding.getRoot(); 

       TransitionManager.beginDelayedTransition(sceneRoot, transition); 

       return true; 
      } 
     });