{"id":266408,"date":"2015-09-25T18:05:03","date_gmt":"2015-09-25T14:05:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=266408"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=266408","title":{"rendered":"Android Data Binding in RecyclerView"},"content":{"rendered":"<p>       <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/ac6\/364\/b41\/ac6364b41862460ab3b24dfe92e5e33e.png\"\/><\/p>\n<p>  \u041d\u0430 Google IO 2015 \u0430\u043d\u043e\u043d\u0441\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u043d\u043e\u0432\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 Data Binding Library. \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0435\u0435 \u0437\u0430\u0434\u0430\u0447\u0430 \u2014 \u0432\u044b\u043d\u0435\u0441\u0435\u043d\u0438\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u0438 View \u0432 xml-\u0444\u0430\u0439\u043b\u044b. \u041e\u043d\u0430 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043a\u043e\u0434\u0430 \u0438 \u0438\u0437\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043e\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u043e\u0432 findByViewId(), \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u0441\u044b\u043b\u043e\u043a \u043d\u0430 view-\u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432\u043d\u0443\u0442\u0440\u0438 Activity\/Fragment\u2019\u043e\u0432. \u0422\u0430\u043a\u0436\u0435 \u043e\u043d\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b, \u043f\u0440\u0438\u0432\u044f\u0437\u044b\u0432\u0430\u044f \u0438\u0445 \u043a \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u043c\u0435\u0442\u043e\u0434\u0430\u043c. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0441\u0442\u0430\u0442\u044c\u0435\u0439 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e Data Binding \u0443\u0436\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e, \u043d\u043e \u043f\u043e \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e \u0432 RecycleView \u0432\u0441\u0435\u0433\u043e \u043d\u0438\u0447\u0435\u0433\u043e, \u0432\u043e\u0441\u043f\u043e\u043b\u043d\u0438\u043c \u044d\u0442\u043e\u0442 \u043f\u0440\u043e\u0431\u0435\u043b.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h5><b>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430<\/b><\/h5>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0437\u0430\u0445\u043e\u0434\u0438\u043c \u0432 \u0444\u0430\u0439\u043b build.gradle, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043b\u0435\u0436\u0438\u0442 \u0432 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u043c \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u0412 \u0431\u043b\u043e\u043a\u0435 dependencies \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c:<\/p>\n<pre><code class=\"java\">buildscript {    repositories {        jcenter()    }    dependencies {        classpath &quot;com.android.tools.build:gradle:1.3.0&quot;        classpath &quot;com.android.databinding:dataBinder:1.0-rc1&quot;    } }  allprojects {    repositories {        jcenter()    } } <\/code><\/pre>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c Data Binding \u043f\u043b\u0430\u0433\u0438\u043d \u043a \u043f\u0440\u043e\u0435\u043a\u0442\u0443. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432 build.gradle \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0442\u0440\u043e\u0447\u043a\u0443 \u0441 \u043f\u043b\u0430\u0433\u0438\u043d\u043e\u043c. \u0422\u0430\u043a\u0436\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0447\u0442\u043e\u0431\u044b compileSdkVersion \u0431\u044b\u043b\u0430 23.<\/p>\n<pre><code class=\"java\">apply plugin: 'com.android.application' apply plugin: 'com.android.databinding' <\/code><\/pre>\n<h5><b>\u0411\u0438\u043d\u0434\u0438\u043d\u0433<\/b><\/h5>\n<p>  \u041f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e xml-\u0444\u0430\u0439\u043b\u0430. \u041e\u043d, \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e, \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u043f\u0430\u043a\u0435 res\/layoyt. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0433\u043e \u0442\u0435\u0433\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c . Android Studio \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0434\u0441\u0432\u0435\u0447\u0438\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043a\u0440\u0430\u0441\u043d\u044b\u043c \u0438\u043b\u0438 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0442\u044c \u0432\u044b\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0448\u0438\u0440\u0438\u043d\u0443 \u0438 \u0432\u044b\u0441\u043e\u0442\u0443, \u043d\u043e \u043c\u044b \u0435\u0435 \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u0435\u043c. <\/p>\n<pre><code class=\"java\">&lt;layout xmlns:android=&quot;http:\/\/schemas.android.com\/apk\/res\/android&quot;     xmlns:app=&quot;http:\/\/schemas.android.com\/apk\/res-auto&quot;&gt;      &lt;data&gt;     &lt;\/data&gt;      &lt;!-- \u0421\u044e\u0434\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0432\u043e\u0439 layout --&gt;   &lt;\/layout&gt; <\/code><\/pre>\n<p>  \u0427\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0441\u044f \u0431\u0438\u043d\u0434\u0435\u0440-\u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u0432\u044f\u0437\u044b\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u043a view, \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u0442\u044c xml \u043a \u043c\u043e\u0434\u0435\u043b\u0438. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432\u043d\u0443\u0442\u0440\u0438 \u0442\u0435\u0433\u0430  \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0438\u043c\u044f \u0438 \u043f\u0443\u0442\u044c \u043a \u043d\u0430\u0448\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044cc\u044f \u0441\u043f\u0438\u0441\u043e\u043a \u0444\u0438\u043b\u044c\u043c\u043e\u0432.<\/p>\n<pre><code class=\"java\">public class Movie {    public boolean isWatched;    public String image;    public String description;    public String title;     public Movie(boolean isWatched, String image, String description, String title) {        this.isWatched = isWatched;        this.image = image;        this.description = description;        this.title = title;    } } <\/code><\/pre>\n<pre><code class=\"java\">&lt;layout xmlns:android=&quot;http:\/\/schemas.android.com\/apk\/res\/android&quot;     xmlns:app=&quot;http:\/\/schemas.android.com\/apk\/res-auto&quot;&gt;     &lt;data&gt;    &lt;variable        name=&quot;movie&quot;        type=&quot;com.example.databinding.Movie&quot; \/&gt;   &lt;\/data&gt;   &lt;!-- \u0421\u044e\u0434\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0432\u043e\u0439 layout --&gt;   &lt;\/layout&gt; <\/code><\/pre>\n<p>  \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u0432\u043e\u0439 layout \u0438 \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u0442\u044c \u043a \u043d\u0435\u043c\u0443 \u043c\u043e\u0434\u0435\u043b\u044c. \u041f\u0443\u0441\u0442\u044c \u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0444\u0438\u043b\u044c\u043c\u0430 \u0431\u0443\u0434\u0435\u0442 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430, \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0438 \u043a\u0440\u0430\u0442\u043a\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435. \u0427\u0442\u043e\u0431\u044b \u0443\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u043f\u043e\u043b\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u0437 \u043c\u043e\u0434\u0435\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u201c@{*\u043a\u0430\u043a\u043e\u0435 \u043f\u043e\u043b\u0435 \u0438\u0437 \u043c\u043e\u0434\u0435\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c*}\u201d.<\/p>\n<pre><code class=\"java\">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt; &lt;layout xmlns:android=&quot;http:\/\/schemas.android.com\/apk\/res\/android&quot;    xmlns:app=&quot;http:\/\/schemas.android.com\/apk\/res-auto&quot;&gt;     &lt;data&gt;        &lt;variable            name=&quot;movie&quot;            type=&quot;com.example.databinding.Movie&quot; \/&gt;    &lt;\/data&gt;     &lt;android.support.v7.widget.CardView        android:layout_width=&quot;match_parent&quot;        android:layout_height=&quot;match_parent&quot;        android:orientation=&quot;vertical&quot;        android:layout_margin=&quot;8dp&quot;&gt;         &lt;RelativeLayout            android:id=&quot;@+id\/relativeLayout&quot;            android:layout_width=&quot;match_parent&quot;            android:layout_height=&quot;wrap_content&quot;&gt;             &lt;ImageView                android:id=&quot;@+id\/imageView&quot;                ...                              app:imageUrl=&quot;@{movie.image}&quot;\/&gt;            &lt;TextView                android:id=&quot;@+id\/textView&quot;                ...                android:text=&quot;@{movie.title}&quot;                android:textAppearance=&quot;?android:attr\/textAppearanceLarge&quot; \/&gt;             &lt;TextView                android:id=&quot;@+id\/textView2&quot;                ...                android:text=&quot;@{movie.description}&quot;                android:textAppearance=&quot;?android:attr\/textAppearanceSmall&quot; \/&gt;         &lt;\/RelativeLayout&gt;     &lt;\/android.support.v7.widget.CardView&gt;  &lt;\/layout&gt; <\/code><\/pre>\n<p>  \u0421 android:text=&quot;@{movie.title}&quot; \u0438 android:text=&quot;@{movie.description}&quot; \u0432\u0441\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u2014 \u043f\u0440\u043e\u0441\u0442\u043e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0442\u0435\u043a\u0441\u0442\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0435 \u043f\u043e\u043b\u0435, \u043d\u043e \u0447\u0442\u043e \u043d\u0430 \u0441\u0447\u0435\u0442 app:imageUrl=&quot;@{movie.image}&quot;? \u0422\u0443\u0442 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0440\u0435\u0430\u043b\u044c\u043d\u0430\u044f \u043c\u0430\u0433\u0438\u044f Data Binding. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u0433\u043e\u0434\u043d\u043e \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0445 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 \u0438 \u0434\u0430\u0436\u0435 \u043d\u0435 \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0438\u0445 \u0432 atts.xml, \u0430 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f  @BindingAdapter() \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0432\u0430\u043c \u0438\u0445 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c. \u041d\u0438\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e, \u043a\u0430\u043a \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438.<\/p>\n<p>  \u041f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0443. \u041d\u0430\u043f\u0438\u0448\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 RecyclerView.Adapter. \u041d\u0430\u0447\u043d\u0435\u043c \u0441 ViewHolder. \u041a\u0430\u043a \u043e\u043d \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b \u0440\u0430\u043d\u044c\u0448\u0435:<\/p>\n<pre><code class=\"java\">public static class MovieItemViewHolder extends RecyclerView.ViewHolder {    private TextView title, description;    private ImageView image;     public ViewHolder(View v) {        super(v);        title = (TextView) v.findViewById(R.id.textView);        description = (TextView) v.findViewById(R.id.textView2);        image = (ImageView) v.findViewById(R.id.imageView);    } } <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u043e\u043d \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b \u043f\u043e\u0441\u043b\u0435 Butterknif:<\/p>\n<pre><code class=\"java\">public static class MovieItemViewHolder extends RecyclerView.ViewHolder {    @Bind(R.id.textView) TextView title;    @Bind(R.id.textView2) TextView description;    @Bind(R.id.imageView) ImageView image;     public ViewHolder(View v) {        super(v);        ButterKnife.bind(v);    } } <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u043e\u043d \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u043e\u0441\u043b\u0435 DataBinding:<\/p>\n<pre><code class=\"java\">public class MovieItemViewHolder extends RecyclerView.ViewHolder {     MovieItemBinding binding;     public MovieItemViewHolder(View v) {        super(v);        binding = DataBindingUtil.bind(v);    } } <\/code><\/pre>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u043d\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0442 \u0434\u0432\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u0430 \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0430: onCreateViewHolder \u0438 onBindViewHolder. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435\u043c \u0438 \u0431\u0438\u043d\u0434\u0438\u0433\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c\u0441\u044f MovieItemBinding. \u041e\u043d \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043f\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044e xml, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u0432\u044b\u0448\u0435. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0444\u0430\u0439\u043b xml \u043d\u0430\u0437\u044b\u0432\u0430\u043b\u0441\u044f movie_item.xml. <\/p>\n<pre><code class=\"java\">@Override public MovieItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {    LayoutInflater inflater = LayoutInflater.from(parent.getContext());    MovieItemBinding binding = MovieItemBinding.inflate(inflater, parent, false);    return new MovieItemViewHolder(binding.getRoot()); } <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a onBindViewHolder, \u043a\u0430\u043a \u043e\u043d \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b \u0440\u0430\u043d\u044c\u0448\u0435:<\/p>\n<pre><code class=\"java\">@Override public void onBindViewHolder(MovieItemViewHolder holder, int position) {    Movie movie = Movie.ITEMS[position];    holder.title.setText(movie.title);    holder.description.setText(movie.description);    Picasso.with(holder.image.getContext()).load(movie.image).into(holder.image); } <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u043e\u043d \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0435\u043f\u0435\u0440\u044c:<\/p>\n<pre><code class=\"java\">@Override public void onBindViewHolder(MovieItemViewHolder holder, int position) {    Movie movie = Movie.ITEMS[position];    holder.binding.setMovie(movie); } <\/code><\/pre>\n<p>  \u041d\u043e \u044d\u0442\u043e \u0435\u0449\u0435 \u043d\u0435 \u0432\u0441\u0451, \u043a\u0430\u043a \u043d\u0430 \u0441\u0447\u0435\u0442 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0433\u043e app:imageUrl=&quot;@{movie.image}&quot;?.. \u041e\u043f\u044f\u0442\u044c \u0436\u0435 \u0432\u0441\u0435 \u043f\u0440\u043e\u0441\u0442\u043e: \u0432\u043d\u0443\u0442\u0440\u0438 \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0430 \u0434\u0435\u043b\u0430\u0435\u043c \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 \u0441 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439  @BindingAdapter. \u0412\u043d\u0443\u0442\u0440\u044c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u043d\u0430\u0448 \u0430\u0442\u0442\u0440\u0438\u0431\u0443\u0442. \u0412 \u0438\u0442\u043e\u0433\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c<\/p>\n<pre><code class=\"java\">@BindingAdapter(&quot;bind:imageUrl&quot;) public static void loadImage(ImageView imageView, String v) {    Picasso.with(imageView.getContext()).load(v).into(imageView); } <\/code><\/pre>\n<p>  \u041d\u0430 \u0432\u0445\u043e\u0434 \u043f\u043e\u0441\u0442\u0443\u043f\u0438\u0442 imageView \u0438 \u0442\u043e \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0441\u0442 \u043c\u043e\u0434\u0435\u043b\u044c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 image. \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0441\u0435 \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442.<\/p>\n<h5><b>\u041e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0441\u0442\u0438<\/b><\/h5>\n<p>  \u0412 \u043c\u043e\u0434\u0435\u043b\u0438 Movie \u0431\u044b\u043b\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f isWatched. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u043c\u044b \u0445\u043e\u0442\u0438\u043c, \u0447\u0442\u043e\u0431\u044b \u0443 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043d\u044b\u0445 \u0438 \u043d\u043e\u0432\u044b\u0445 \u0444\u0438\u043b\u044c\u043c\u043e\u0432 \u0431\u044b\u043b\u0438 \u0440\u0430\u0437\u043d\u044b\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043d\u0430 \u043a\u043b\u0438\u043a. \u0421 DataBinding\u2019\u043e\u043c \u0442\u0435\u043f\u0435\u0440\u044c \u044d\u0442\u043e \u043f\u0440\u043e\u0449\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e. \u041d\u0430\u043f\u0438\u0448\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043d\u0430\u0436\u0430\u0442\u0438\u044f \u0434\u043b\u044f \u0444\u0438\u043b\u044c\u043c\u0430.<\/p>\n<pre><code class=\"java\">public interface MovieClickHandler{    void onNewClick(View view);    void onWatchedClick(View view); } <\/code><\/pre>\n<p>  \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0435\u0433\u043e \u0432 xml-\u0444\u0430\u0439\u043b \u0432 \u0442\u0435\u0433 data.<\/p>\n<pre><code class=\"java\">...     &lt;data&gt;        ...        &lt;variable name=&quot;click&quot; type=&quot;com.example.databinding.MovieClickHandler&quot; \/&gt;     &lt;\/data&gt; ...            &lt;ImageView             ...            android:onClick=&quot;@{movie.isWatched ? click.onWatchedClick : click.onNewClick}&quot;\/&gt;           ... <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0430 onBindViewHolder \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0441\u0435\u0442\u0438\u0442\u044c \u043d\u0430\u0448 \u043b\u0438\u0441\u0435\u043d\u0435\u0440. \u041a\u0430\u043a \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u0431\u0438\u043d\u0434\u0435\u0440\u043e\u043c, \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c\u0443 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0432 xml-\u0444\u0430\u0439\u043b\u0435.<\/p>\n<pre><code class=\"java\">public void onBindViewHolder(MovieItemViewHolder holder, int position) {    Movie movie = Movie.ITEMS[position];    holder.binding.setMovie(movie);    holder.binding.setClick(new MovieClickHandler() {        @Override        public void onWatchedClick(View view) {         }         @Override        public void onOldClick(View view) {         }    }); } <\/code><\/pre>\n<p>  \u041f\u0443\u0441\u0442\u044c \u043f\u043e \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430 \u0443 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043d\u044b\u0445 \u0444\u0438\u043b\u044c\u043c\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u0447\u0435\u0440\u043d\u043e-\u0431\u0435\u043b\u0430\u044f. \u0414\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043d\u043e\u0432\u044b\u0439 \u0430\u0442\u0440\u0438\u0431\u0443\u0442. <\/p>\n<pre><code class=\"java\">&lt;ImageView    ...    app:filter='@{movie.isWatched ? &quot;grey&quot; : null}'    ...\/&gt; <\/code><\/pre>\n<p>  \u0412 \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0435 \u0447\u0435\u0440\u0435\u0437  @BindingAdapter \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443<\/p>\n<pre><code class=\"java\">@BindingAdapter(&quot;bind:filter&quot;) public static void applyFilter(ImageView imageView, String v) {    imageView.setColorFilter(null);    if(&quot;grey&quot;.equals(v)){        ColorMatrix matrix = new ColorMatrix();        matrix.setSaturation(0);        ColorMatrixColorFilter cf = new ColorMatrixColorFilter(matrix);        imageView.setColorFilter(cf);    } } <\/code><\/pre>\n<p>  \u0422\u0430\u043a\u0436\u0435 \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0430\u0431\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0435\u0441\u043b\u0438 \u043e\u0434\u043d\u043e \u0438\u0437 \u043f\u043e\u043b\u0435\u0439 \u043f\u0443\u0441\u0442\u043e\u0435.<\/p>\n<pre><code class=\"java\">&lt;TextView    ...    android:text='@{movie.title ?? &quot;unknown&quot;}'    ... \/&gt; <\/code><\/pre>\n<p>  \u0421\u0442\u043e\u0438\u0442 \u0442\u0430\u043a\u0436\u0435 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0432\u043d\u0443\u0442\u0440\u0438 MovieItemBinding \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u0441\u044f \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0432\u0441\u0435 view, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0435\u0441\u0442\u044c ID \u0432 xml-\u0444\u0430\u0439\u043b\u0435. <\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/939\/7f6\/809\/9397f6809f7f490e96de7e76f6d5fd50.png\"\/><\/p>\n<h5><b>\u0418\u0442\u043e\u0433<\/b><\/h5>\n<p>  \u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043e\u0447\u0435\u043d\u044c \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 RecycleView, \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u0434\u0430 \u043f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u0442\u0441\u044f \u0432 \u0440\u0430\u0437\u044b, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0438\u043a\u0430\u043a\u0438\u0445 if\/else \u0434\u043b\u044f \u043a\u043e\u043b\u0431\u0435\u043a\u043e\u0432 \u0438 \u0434\u0430\u043d\u043d\u044b\u0445. \u0421 JavaRX \u043c\u043e\u0436\u043d\u043e \u0435\u0449\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u043e\u043a\u0430 \u043f\u0440\u0430\u0432\u0434\u0430 \u043e\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043e\u0434\u043d\u0443 \u0441\u0442\u043e\u0440\u043e\u043d\u0443: \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442\u0441\u044f UI, \u043d\u043e \u043d\u0435 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442.<\/p>\n<p>  <b>\u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438<\/b>:<\/p>\n<p>  <a href=\"https:\/\/github.com\/HellCat24\/DataBindingInRecycle\">\u0422\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442.<\/a><br \/>  <a href=\"https:\/\/developer.android.com\/tools\/data-binding\/guide.html\">\u041e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f.<\/a><br \/>  <a href=\"http:\/\/habrahabr.ru\/post\/260317\/\">\u0411\u044b\u0441\u0442\u0440\u044b\u0439 \u0441\u0442\u0430\u0440\u0442 Data Binding \u0432 Android.<\/a>               <\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/267735\/\"> http:\/\/habrahabr.ru\/post\/267735\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/ac6\/364\/b41\/ac6364b41862460ab3b24dfe92e5e33e.png\"\/><\/p>\n<p>  \u041d\u0430 Google IO 2015 \u0430\u043d\u043e\u043d\u0441\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u043d\u043e\u0432\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 Data Binding Library. \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0435\u0435 \u0437\u0430\u0434\u0430\u0447\u0430 \u2014 \u0432\u044b\u043d\u0435\u0441\u0435\u043d\u0438\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u0438 View \u0432 xml-\u0444\u0430\u0439\u043b\u044b. \u041e\u043d\u0430 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043a\u043e\u0434\u0430 \u0438 \u0438\u0437\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043e\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u043e\u0432 findByViewId(), \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u0441\u044b\u043b\u043e\u043a \u043d\u0430 view-\u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432\u043d\u0443\u0442\u0440\u0438 Activity\/Fragment\u2019\u043e\u0432. \u0422\u0430\u043a\u0436\u0435 \u043e\u043d\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b, \u043f\u0440\u0438\u0432\u044f\u0437\u044b\u0432\u0430\u044f \u0438\u0445 \u043a \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u043c\u0435\u0442\u043e\u0434\u0430\u043c. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0441\u0442\u0430\u0442\u044c\u0435\u0439 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e Data Binding \u0443\u0436\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e, \u043d\u043e \u043f\u043e \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e \u0432 RecycleView \u0432\u0441\u0435\u0433\u043e \u043d\u0438\u0447\u0435\u0433\u043e, \u0432\u043e\u0441\u043f\u043e\u043b\u043d\u0438\u043c \u044d\u0442\u043e\u0442 \u043f\u0440\u043e\u0431\u0435\u043b.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-266408","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/266408","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=266408"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/266408\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=266408"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=266408"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=266408"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}