Android Data Binding的示范項目
介紹:
Android Data Binding的示范項目。用retrofit請求一列數據然后顯示在RecyclerView上。在actionbar的SearchView控件上輸入github賬戶名,應用就會使用Retrofit查詢GitHub的api,借助data bindig將結果反饋到RecyclerView上。
運行效果:

使用說明:
需要Android Studio 1.3.0-beta1以上。
Classpath 依賴
classpath 'com.android.tools.build:gradle:1.2.3' classpath 'com.android.databinding:dataBinder:1.0-rc0'
插件
apply plugin: ‘com.android.application' apply plugin: 'com.android.databinding'
布局
<?xml version="1.0" encoding="utf-8"?> <layout xmlns:android="http://schemas.android.com/apk/res/android"> <data> <variable name="user" type="com.example.User"/> </data> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@{user.firstName}" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@{user.lastName}" /> </LinearLayout> </layout>
Activity
ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.main_activity); User user = new User("Test", "User"); binding.setUser(user);
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!