Posts

Showing posts with the label databinding

Databinding in RecyclerView - Android - Kotlin

Image
Hey Guyss!! Already we have seen the basics of Databinding and how to use it in previous  post . Now let's see how to use Databinding in RecyclerView . And Its gonna be a short post. ;) You can find the Project in GitHub . Prerequisite: build.gradle First, we have enable dataBinding in app-level build.gradle                           android {                                     dataBinding {                                             enabled = true                                     }                            } Next, we have add the following plugin.                               apply plugin: 'kotlin-kapt'  Next, we have to include dependency for databinding, (Not needed, if using Android Studio 3.2 or above, since its already bundled)                             kapt "com.android.databinding:compiler:3.2.0-alpha10" Implementation: We can directly bind the data to RecyclerView's Adapter layout. So, let's design the

Exploring Databinding Library in Android - Kotlin

Image
Introduction: Data binding library is a support library, which allows us to bind data sources directly to UI components of layout file. Binding components this way, reduces boilerplate code in our business logic where we usually update UI when new data is available. It also improves app's performance and helps to prevent memory leak and NullPointerException. textView.text = user.name can be written simply in layout as follows, and no need to write in Activity class.                                                             <TextView                                                                   ...                                                                   android:text="@{user.name}" /> You can find the project in Github . Prerequisite: build.gradle First, we have enable dataBinding in app-level build.gradle                            android {                                     dataBinding {