1 package com.android.example.bindingdemo.vo; 2 3 import android.databinding.Bindable; 4 import android.graphics.Color; 5 6 import android.databinding.BaseObservable; 7 import com.android.example.bindingdemo.BR; 8 9 import java.util.Objects; 10 11 public class User extends BaseObservable { 12 @Bindable 13 private String name; 14 @Bindable 15 private String lastName; 16 @Bindable 17 private int photoResource = 0; 18 @Bindable 19 private int favoriteColor = Color.RED; 20 @Bindable 21 private int group; 22 public static final int KITTEN = 1; 23 public static final int ROBOT = 2; 24 User(String name, String lastName, int photoResource, int group)25 public User(String name, String lastName, int photoResource, int group) { 26 this.name = name; 27 this.lastName = lastName; 28 this.photoResource = photoResource; 29 this.group = group; 30 } 31 setGroup(int group)32 public void setGroup(int group) { 33 if (this.group == group) { 34 return; 35 } 36 this.group = group; 37 notifyPropertyChanged(BR.group); 38 } 39 getGroup()40 public int getGroup() { 41 return group; 42 } 43 getName()44 public String getName() { 45 return name; 46 } 47 setName(String name)48 public void setName(String name) { 49 if (Objects.equals(name, this.name)) { 50 return; 51 } 52 this.name = name; 53 notifyPropertyChanged(BR.name); 54 } 55 getLastName()56 public String getLastName() { 57 return lastName; 58 } 59 setLastName(String lastName)60 public void setLastName(String lastName) { 61 if (Objects.equals(lastName, this.lastName)) { 62 return; 63 } 64 this.lastName = lastName; 65 notifyPropertyChanged(BR.lastName); 66 } 67 getPhotoResource()68 public int getPhotoResource() { 69 return photoResource; 70 } 71 setPhotoResource(int photoResource)72 public void setPhotoResource(int photoResource) { 73 if (this.photoResource == photoResource) { 74 return; 75 } 76 this.photoResource = photoResource; 77 notifyPropertyChanged(BR.photoResource); 78 } 79 getFavoriteColor()80 public int getFavoriteColor() { 81 return favoriteColor; 82 } 83 } 84