Site icon C1CTech

Android Jetpack Data Binding

<p class&equals;"p1">In this article&comma; we are going to learn the basics of <strong><span style&equals;"color&colon; &num;008000&semi;">DataBinding<&sol;span><&sol;strong> with an emphasis on explaining how data binding is implemented within an Android Studio project&period;<&sol;p>&NewLine;<h3 class&equals;"p1"><span style&equals;"color&colon; &num;000080&semi;"><strong>Data Binding <&sol;strong><&sol;span><&sol;h3>&NewLine;<p><span style&equals;"color&colon; &num;0000ff&semi;"><strong>DataBinding<&sol;strong><&sol;span> is one of the <span style&equals;"color&colon; &num;008000&semi;"><strong>Android Jetpack Architecture Component<&sol;strong><&sol;span> suggested by android&period; The <span style&equals;"color&colon; &num;000000&semi;">Data Binding<&sol;span> Library is a support library that allows you to directly connect the views in a user interface layout to the methods and data located in other objects within an app without the need to write code&period;<&sol;p>&NewLine;<h3 class&equals;"p1"><span style&equals;"color&colon; &num;000080&semi;"><strong>The Key Components of Data Binding<&sol;strong><&sol;span><&sol;h3>&NewLine;<p class&equals;"p1">By default&comma; an Android Studio project is not configured for data binding support&period; In fact&comma; a number of different elements need to be combined before an app can begin making use of data binding&period; These involve the project build configuration&comma; the layout XML file&comma; data binding classes and use of the data binding expression language&period; Don&&num;8217&semi;t worry these are actually quite simple steps which we will cover in detail&period;<&sol;p>&NewLine;<h4 class&equals;"p1"><span style&equals;"color&colon; &num;0000ff&semi;"><strong>The Project Build Configuration<&sol;strong><&sol;span><&sol;h4>&NewLine;<p class&equals;"p1">Before a project can make use of data binding it must first be configured to make use of the Android Data Binding Library and to enable support for data binding classes and the binding expression syntax&period;<&sol;p>&NewLine;<p class&equals;"p1">Open the <span style&equals;"color&colon; &num;008000&semi;"><strong>build&period;gradle<&sol;strong><&sol;span> located under <span style&equals;"color&colon; &num;0000ff&semi;"><strong>app<&sol;strong><&sol;span> and enable <b><span style&equals;"color&colon; &num;008000&semi;">data binding<&sol;span> <&sol;b>under<b><span style&equals;"color&colon; &num;0000ff&semi;"> android<&sol;span> <&sol;b>module<b>&period; <&sol;b>Once enabled&comma; Sync the project&period;<&sol;p>&NewLine;<p><strong><span style&equals;"color&colon; &num;0000ff&semi;">app&sol;build&period;gradle<&sol;span><&sol;strong><&sol;p>&NewLine;<pre>android &lbrace;&NewLine;&NewLine;<span style&equals;"color&colon; &num;008000&semi;"><strong>dataBinding &lbrace; &NewLine; enabled &equals; true &NewLine; &rcub;&NewLine;<&sol;strong><&sol;span>&NewLine;compileSdkVersion 29&NewLine;buildToolsVersion "29&period;0&period;2"&NewLine;&colon;&NewLine;&colon;&NewLine;versionName "1&period;0"&NewLine;testInstrumentationRunner "androidx&period;test&period;runner&period;AndroidJUnitRunner"&NewLine;&rcub;<&sol;pre>&NewLine;<h4 class&equals;"p1"><span style&equals;"color&colon; &num;0000ff&semi;"><strong>The Data Binding Layout File<&sol;strong><&sol;span><&sol;h4>&NewLine;<p class&equals;"p1">The user interfaces for an app are typically contained within an XML layout file&period; Before the views contained within one of these layout files can take advantage of data binding&comma; the layout file must first be converted to a <strong><span style&equals;"color&colon; &num;008000&semi;">data binding layout<&sol;span><&sol;strong> file&period;<&sol;p>&NewLine;<p class&equals;"p1">XML layout files define the hierarchy of components in the layout starting with a top-level or root view&period; This root view takes the form of a layout container such as a ConstraintLayout&comma; FrameLayout or LinearLayout &colon;<&sol;p>&NewLine;<pre>&lt&semi;&quest;xml version&equals;"1&period;0" encoding&equals;"utf-8"&quest;&gt&semi;&NewLine;&lt&semi;androidx&period;constraintlayout&period;widget&period;ConstraintLayout xmlns&colon;android&equals;"http&colon;&sol;&sol;schemas&period;android&period;com&sol;apk&sol;res&sol;android"&NewLine; xmlns&colon;app&equals;"http&colon;&sol;&sol;schemas&period;android&period;com&sol;apk&sol;res-auto"&NewLine; xmlns&colon;tools&equals;"http&colon;&sol;&sol;schemas&period;android&period;com&sol;tools"&NewLine; android&colon;layout&lowbar;width&equals;"match&lowbar;parent"&NewLine; android&colon;layout&lowbar;height&equals;"match&lowbar;parent"&NewLine; tools&colon;context&equals;"&period;MainActivity"&gt&semi;&NewLine; &period;&NewLine; &period;&NewLine; &period;&NewLine;&lt&semi;&sol;androidx&period;constraintlayout&period;widget&period;ConstraintLayout&gt&semi;<&sol;pre>&NewLine;<p class&equals;"p1">In order to be able to use data binding&comma; the layout hierarchy must have a <strong><span style&equals;"color&colon; &num;008000&semi;">layout<&sol;span><&sol;strong> component as the <strong><span style&equals;"color&colon; &num;008000&semi;">root view<&sol;span><&sol;strong> which&comma; in turn&comma; becomes the parent of the current root view&period;<&sol;p>&NewLine;<p>To convert the above layout file into data binding layout file we have to do  the following changes&colon;<&sol;p>&NewLine;<pre>&lt&semi;&quest;xml version&equals;"1&period;0" encoding&equals;"utf-8"&quest;&gt&semi;&NewLine;&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;">&lt&semi;layout<&sol;span><&sol;strong>&NewLine; xmlns&colon;android&equals;"http&colon;&sol;&sol;schemas&period;android&period;com&sol;apk&sol;res&sol;android"&NewLine; xmlns&colon;app&equals;"http&colon;&sol;&sol;schemas&period;android&period;com&sol;apk&sol;res-auto"&NewLine; xmlns&colon;tools&equals;"http&colon;&sol;&sol;schemas&period;android&period;com&sol;tools"&gt&semi;&NewLine;&NewLine;&lt&semi;androidx&period;constraintlayout&period;widget&period;ConstraintLayout &NewLine; android&colon;layout&lowbar;width&equals;"match&lowbar;parent"&NewLine; android&colon;layout&lowbar;height&equals;"match&lowbar;parent"&NewLine; tools&colon;context&equals;"&period;MainActivity"&gt&semi;&NewLine; &period;&NewLine; &period;&NewLine; &period;&NewLine;&lt&semi;&sol;androidx&period;constraintlayout&period;widget&period;ConstraintLayout&gt&semi;&NewLine;&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;">&lt&semi;&sol;layout&gt&semi;<&sol;span><&sol;strong><&sol;pre>&NewLine;<h4 class&equals;"p1"><span style&equals;"color&colon; &num;0000ff&semi;"><strong>The Layout File Data Element<&sol;strong><&sol;span><&sol;h4>&NewLine;<p class&equals;"p1">The data binding layout file needs some way to declare the classes within the project to which the views in the layout are to be bound&period; Having declared these classes&comma; the layout file will also need a <span style&equals;"color&colon; &num;008000&semi;"><strong>variable<&sol;strong><&sol;span> name by which to reference those instances within <strong><span style&equals;"color&colon; &num;008000&semi;">binding expressions<&sol;span><&sol;strong>&period;<&sol;p>&NewLine;<p class&equals;"p1">This is achieved using the <span style&equals;"color&colon; &num;008000&semi;"><strong>data element<&sol;strong><&sol;span>&comma; an example of which is shown below&colon;<&sol;p>&NewLine;<pre>&lt&semi;&quest;xml version&equals;"1&period;0" encoding&equals;"utf-8"&quest;&gt&semi;&NewLine;&NewLine;<span style&equals;"color&colon; &num;008000&semi;"><strong>&lt&semi;layout<&sol;strong><&sol;span>&NewLine; xmlns&colon;android&equals;"http&colon;&sol;&sol;schemas&period;android&period;com&sol;apk&sol;res&sol;android"&NewLine; xmlns&colon;app&equals;"http&colon;&sol;&sol;schemas&period;android&period;com&sol;apk&sol;res-auto"&NewLine; xmlns&colon;tools&equals;"http&colon;&sol;&sol;schemas&period;android&period;com&sol;tools"&gt&semi;&NewLine;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;"> &lt&semi;data&gt&semi;      <&sol;span><&sol;strong>&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;"> &lt&semi;variable<&sol;span><&sol;strong>&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;"> name&equals;"user"<&sol;span><&sol;strong>&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;"> type&equals;"com&period;example&period;databindingdemo&period;User" &sol;&gt&semi;  <&sol;span><&sol;strong>&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;"> &lt&semi;&sol;data&gt&semi;<&sol;span><&sol;strong>&NewLine;&NewLine;&lt&semi;androidx&period;constraintlayout&period;widget&period;ConstraintLayout&NewLine; android&colon;layout&lowbar;width&equals;"match&lowbar;parent"&NewLine; android&colon;layout&lowbar;height&equals;"match&lowbar;parent"&NewLine; tools&colon;context&equals;"&period;MainActivity"&gt&semi;&NewLine; &period;&NewLine; &period;&NewLine; &period;&NewLine;&lt&semi;&sol;androidx&period;constraintlayout&period;widget&period;ConstraintLayout&gt&semi;&NewLine;&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;">&lt&semi;&sol;layout&gt&semi;<&sol;span><&sol;strong><&sol;pre>&NewLine;<p class&equals;"p1">The above <span style&equals;"color&colon; &num;008000&semi;"><strong>data<&sol;strong><&sol;span> element declares a new variable named <span style&equals;"color&colon; &num;008000&semi;"><strong>user<&sol;strong><&sol;span> of type <span style&equals;"color&colon; &num;008000&semi;"><strong>User<&sol;strong><&sol;span> &period;<&sol;p>&NewLine;<p class&equals;"p1"><span style&equals;"color&colon; &num;008000&semi;"><strong><span style&equals;"color&colon; &num;0000ff&semi;">Note&colon; <&sol;span> it is necessary to declare the full package name of the User class when declaring the variable&period;<&sol;strong><&sol;span><&sol;p>&NewLine;<h4 id&equals;"imports&lowbar;variables&lowbar;and&lowbar;includes"><span style&equals;"color&colon; &num;0000ff&semi;"><strong>Imports&comma; variables&comma; and includes<&sol;strong><&sol;span><&sol;h4>&NewLine;<p>The Data Binding Library provides features such as imports&comma; variables&comma; and includes&period;<&sol;p>&NewLine;<ul>&NewLine;<li><strong><span style&equals;"color&colon; &num;0000ff&semi;">Imports <&sol;span><&sol;strong>make easy to reference classes inside your layout files&period;<&sol;li>&NewLine;<li><strong><span style&equals;"color&colon; &num;0000ff&semi;">Variables<&sol;span><&sol;strong> allow you to describe a property that can be used in binding expressions&period;<&sol;li>&NewLine;<li><strong><span style&equals;"color&colon; &num;0000ff&semi;">Includes<&sol;span><&sol;strong> let you reuse complex layouts across your app&period;<&sol;li>&NewLine;<&sol;ul>&NewLine;<h5><span style&equals;"color&colon; &num;000080&semi;"><strong>Imports<&sol;strong><&sol;span><&sol;h5>&NewLine;<p class&equals;"p1">The data element can also import other classes that may then be referenced within binding expressions elsewhere in the layout file&period;<&sol;p>&NewLine;<p class&equals;"p1">For example&comma; the following code example imports the <span style&equals;"color&colon; &num;008000&semi;"><strong><span class&equals;"s1">View<&sol;span><&sol;strong><&sol;span> class to the layout file&colon;<&sol;p>&NewLine;<pre>&lt&semi;data&gt&semi;&NewLine; <span style&equals;"color&colon; &num;008000&semi;"><strong>&lt&semi;import type&equals;"android&period;view&period;View"&sol;&gt&semi;<&sol;strong><&sol;span>&NewLine;&lt&semi;&sol;data&gt&semi;<&sol;pre>&NewLine;<p class&equals;"p1">Importing the <span style&equals;"color&colon; &num;008000&semi;"><strong><span class&equals;"s1">View<&sol;span><&sol;strong><&sol;span> class allows you to reference it from your binding expressions&period; The following example shows how to reference the <span style&equals;"color&colon; &num;000000&semi;"><strong><span class&equals;"s1">VISIBLE<&sol;span><&sol;strong><&sol;span> and <strong><span class&equals;"s1">GONE<&sol;span><&sol;strong> constants of the <span class&equals;"s2">View<&sol;span> class&colon;<&sol;p>&NewLine;<pre>&lt&semi;TextView&NewLine;<span style&equals;"color&colon; &num;000000&semi;">android&colon;text&equals;"&commat;&lbrace;user&period;lastName&rcub;"<&sol;span>&NewLine;android&colon;layout&lowbar;width&equals;"wrap&lowbar;content"&NewLine;android&colon;layout&lowbar;height&equals;"wrap&lowbar;content"&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;">android&colon;visibility&equals;"&commat;&lbrace;user&period;isAdult &quest; View&period;VISIBLE &colon; View&period;GONE&rcub;"<&sol;span><&sol;strong>&sol;&gt&semi;<&sol;pre>&NewLine;<p>To import the <span style&equals;"color&colon; &num;008000&semi;"><strong>User<&sol;strong><&sol;span> class in binding layout file we have to write&colon;<&sol;p>&NewLine;<pre>&lt&semi;data&gt&semi;&NewLine; <span style&equals;"color&colon; &num;008000&semi;"><strong> &lt&semi;import type&equals;"com&period;example&period;databindingdemo&period;User" &sol;&gt&semi;<&sol;strong><&sol;span>&NewLine;&NewLine; &lt&semi;variable&NewLine; name&equals;"user"&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;">type&equals;"User"<&sol;span><&sol;strong> &sol;&gt&semi;&NewLine;&lt&semi;&sol;data&gt&semi;<&sol;pre>&NewLine;<h5><span style&equals;"color&colon; &num;000080&semi;"><strong>Variables<&sol;strong><&sol;span><&sol;h5>&NewLine;<p class&equals;"p1"><span style&equals;"color&colon; &num;008000&semi;"><strong>V<span class&equals;"s1">ariable<&sol;span><&sol;strong><&sol;span> element describes a property that may be set on the layout to be used in binding expressions within the layout file&period; You can use multiple <span class&equals;"s1">variable<&sol;span> elements inside the <span class&equals;"s1">data<&sol;span> element&period;<&sol;p>&NewLine;<p class&equals;"p1">The following example declares the <span class&equals;"s1">user<&sol;span>&comma; <span class&equals;"s1">image<&sol;span>&comma; and <span class&equals;"s1">note<&sol;span> variables&colon;<&sol;p>&NewLine;<pre>&lt&semi;data&gt&semi;&NewLine;&lt&semi;import type&equals;"android&period;graphics&period;drawable&period;Drawable"&sol;&gt&semi;&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;">&lt&semi;variable name&equals;"user" type&equals;"com&period;example&period;User"&sol;&gt&semi;<&sol;span><&sol;strong>&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;">&lt&semi;variable name&equals;"image" type&equals;"Drawable"&sol;&gt&semi;<&sol;span><&sol;strong>&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;">&lt&semi;variable name&equals;"note" type&equals;"String"&sol;&gt&semi;<&sol;span><&sol;strong>&NewLine;&lt&semi;&sol;data&gt&semi;<&sol;pre>&NewLine;<h5><span style&equals;"color&colon; &num;000080&semi;"><strong>Includes<&sol;strong><&sol;span><&sol;h5>&NewLine;<p>Variables may be passed into an included layout&&num;8217&semi;s binding from the containing layout by using the app namespace and the variable name in an attribute&period; The following example shows included <span style&equals;"color&colon; &num;008000&semi;"><strong><span class&equals;"s1">user<&sol;span><&sol;strong><&sol;span> variable from the <span style&equals;"color&colon; &num;0000ff&semi;"><strong><span class&equals;"s1">name&period;xml<&sol;span><&sol;strong><&sol;span> and <strong><span class&equals;"s1" style&equals;"color&colon; &num;0000ff&semi;">contact&period;xml<&sol;span><&sol;strong> layout files&colon;<&sol;p>&NewLine;<pre>&lt&semi;&quest;xml version&equals;"1&period;0" encoding&equals;"utf-8"&quest;&gt&semi;&NewLine;&lt&semi;layout xmlns&colon;android&equals;"http&colon;&sol;&sol;schemas&period;android&period;com&sol;apk&sol;res&sol;android"&NewLine;xmlns&colon;bind&equals;"http&colon;&sol;&sol;schemas&period;android&period;com&sol;apk&sol;res-auto"&gt&semi;&NewLine;&NewLine;&lt&semi;data&gt&semi;&NewLine; &lt&semi;variable name&equals;"user" type&equals;"com&period;example&period;User"&sol;&gt&semi;&NewLine;&lt&semi;&sol;data&gt&semi;&NewLine;&NewLine;&lt&semi;LinearLayout&NewLine; android&colon;orientation&equals;"vertical"&NewLine; android&colon;layout&lowbar;width&equals;"match&lowbar;parent"&NewLine; android&colon;layout&lowbar;height&equals;"match&lowbar;parent"&gt&semi;&NewLine;&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;"> &lt&semi;include layout&equals;"&commat;layout&sol;name"<&sol;span><&sol;strong>&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;"> bind&colon;user&equals;"&commat;&lbrace;user&rcub;"&sol;&gt&semi;<&sol;span><&sol;strong>&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;"> &lt&semi;include layout&equals;"&commat;layout&sol;contact"<&sol;span><&sol;strong>&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;"> bind&colon;user&equals;"&commat;&lbrace;user&rcub;"&sol;&gt&semi;<&sol;span><&sol;strong>&NewLine;&lt&semi;&sol;LinearLayout&gt&semi;&NewLine;&lt&semi;&sol;layout&gt&semi;<&sol;pre>&NewLine;<h4 class&equals;"p1"><span style&equals;"color&colon; &num;0000ff&semi;"><strong>The Binding Classes<&sol;strong><&sol;span><&sol;h4>&NewLine;<p>The Data Binding Library generates <span style&equals;"color&colon; &num;008000&semi;"><strong>binding<&sol;strong><&sol;span> classes for each data binding layout file and is used to access the layout&&num;8217&semi;s variables and views&period;<&sol;p>&NewLine;<p class&equals;"p1">This is a subclass of the Android <span style&equals;"color&colon; &num;008000&semi;"><strong>ViewDataBinding<&sol;strong><&sol;span> class and will be named based on the layout filename using word capitalization and the <strong><span style&equals;"color&colon; &num;008000&semi;">Binding<&sol;span><&sol;strong> suffix&period; The binding class for a layout file named <strong><span style&equals;"color&colon; &num;008000&semi;">main&lowbar;activity&period;xml<&sol;span><&sol;strong> file&comma; therefore&comma;will be named <span style&equals;"color&colon; &num;008000&semi;"><b>MainActivityBinding&period;<&sol;b><&sol;span><&sol;p>&NewLine;<p class&equals;"p1">This class holds all the bindings from the layout properties &lpar;for example&comma; the <span class&equals;"s1">user<&sol;span> variable&rpar; to the layout&&num;8217&semi;s views and knows how to assign values for the binding expressions&period;<&sol;p>&NewLine;<h5><span style&equals;"color&colon; &num;0000ff&semi;"><strong>Create a binding object<&sol;strong><&sol;span><&sol;h5>&NewLine;<p class&equals;"p1">Although the binding class is generated automatically&comma; code still needs to be written to create an instance of the class based on the corresponding data binding layout file&period; Fortunately&comma; this can be achieved by making use of the <strong><span style&equals;"color&colon; &num;008000&semi;">DataBindingUtil<&sol;span><&sol;strong> class&period;<&sol;p>&NewLine;<p class&equals;"p1">The initialization code for an Activity or Fragment will typically set the content view or &OpenCurlyDoubleQuote;inflate” the user interface layout file&period;<&sol;p>&NewLine;<p class&equals;"p1">In the case of an existing Activity class&comma; the code to achieve this can be found in the <strong><span style&equals;"color&colon; &num;008000&semi;">onCreate&lpar;&rpar;<&sol;span><&sol;strong> method and will read as follows&colon;<&sol;p>&NewLine;<pre>setContentView&lpar;R&period;layout&period;activity&lowbar;main&rpar;&semi;<&sol;pre>&NewLine;<p>To create the binding class instances within an Activity class is to modify this initialization code as follows&colon;<&sol;p>&NewLine;<pre>ActivityMainBinding binding&semi;&NewLine;&NewLine;binding &equals; DataBindingUtil&period;setContentView&lpar;this&comma; R&period;layout&period;activity&lowbar;main&rpar;&semi;<&sol;pre>&NewLine;<p class&equals;"p1">If you are using data binding items inside a <strong><span class&equals;"s1" style&equals;"color&colon; &num;008000&semi;">Fragment<&sol;span><&sol;strong>&comma; <strong><span class&equals;"s1" style&equals;"color&colon; &num;008000&semi;">ListView<&sol;span><&sol;strong>&comma; or <strong><span class&equals;"s1" style&equals;"color&colon; &num;008000&semi;">RecyclerView<&sol;span><&sol;strong> adapter&comma; you may prefer to use the <span style&equals;"color&colon; &num;008000&semi;"><strong><span class&equals;"s1">inflate&lpar;&rpar;<&sol;span><&sol;strong><&sol;span> methods of the bindings classes or the <strong><span class&equals;"s1" style&equals;"color&colon; &num;008000&semi;">DataBindingUtil<&sol;span><&sol;strong> class&comma; as shown in the following code example&colon;<&sol;p>&NewLine;<pre>FragmentMainBinding binding&semi;&NewLine;binding &equals; FragmentMainBinding&period;inflate&lpar;layoutInflater&comma; viewGroup&comma; false&rpar;&semi;&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol;or<&sol;span><&sol;strong>&NewLine;binding &equals; DataBindingUtil&period;inflate&lpar;inflater&comma; R&period;layout&period;main&lowbar;fragment&comma; container&comma; false&rpar;&semi;&NewLine;&NewLine;View view &equals; binding&period;getRoot&lpar;&rpar;&semi;&NewLine;return view&semi;<&sol;pre>&NewLine;<h4 class&equals;"p1"><span style&equals;"color&colon; &num;0000ff&semi;"><strong>Data Binding Variable Configuration<&sol;strong><&sol;span><&sol;h4>&NewLine;<p>The data binding layout file contains the data element which contains <strong><span style&equals;"color&colon; &num;008000&semi;">variable<&sol;span><&sol;strong> elements consisting of variable names and the class types to which the bindings are to be established&period; For example&colon;<&sol;p>&NewLine;<&excl;-- WP QUADS Content Ad Plugin v&period; 2&period;0&period;98&period;1 -->&NewLine;<div class&equals;"quads-location quads-ad2" id&equals;"quads-ad2" style&equals;"float&colon;none&semi;margin&colon;0px&semi;">&NewLine;&NewLine;<&sol;div>&NewLine;&NewLine;<pre>&lt&semi;data&gt&semi;&NewLine; &lt&semi;variable&NewLine; name&equals;"person"&NewLine; type&equals;"com&period;example&period;databindingdemo&period;User" &sol;&gt&semi;&NewLine;&lt&semi;&sol;data&gt&semi;<&sol;pre>&NewLine;<p class&equals;"p1">The generated binding class has a <strong><span style&equals;"color&colon; &num;008000&semi;">setter and getter<&sol;span><&sol;strong> for each variable declared in the layout&period; The variables take the default managed code values until the setter is called—<span class&equals;"s1">null<&sol;span> for reference types&comma; <span class&equals;"s1">0<&sol;span> for <span class&equals;"s1">int<&sol;span>&comma; <span class&equals;"s1">false<&sol;span> for <span class&equals;"s1">boolean<&sol;span>&comma; etc&period;<&sol;p>&NewLine;<p>The <strong><span style&equals;"color&colon; &num;008000&semi;">person<&sol;span><&sol;strong> variable knows that it will be binding to an instance of a <strong><span style&equals;"color&colon; &num;008000&semi;">User<&sol;span><&sol;strong> class but has not yet been connected to an actual <span style&equals;"color&colon; &num;008000&semi;"><strong>User<&sol;strong><&sol;span> object instance&period;<&sol;p>&NewLine;<p>This is performed via a call to the <strong><span style&equals;"color&colon; &num;008000&semi;">setPerson&lpar;&rpar;<&sol;span><&sol;strong> method&lpar;setter method of person variable&rpar; of the data binding instance as shown below&colon;<&sol;p>&NewLine;<pre>ActivityMainBinding binding&semi;&NewLine;&NewLine;binding &equals; DataBindingUtil&period;setContentView&lpar;this&comma;R&period;layout&period;activity&lowbar;main&rpar;&semi;&NewLine;&NewLine;User user&equals; new User&lpar;"Arun"&comma;"Chandravanshi"&rpar;&semi;&NewLine;<span style&equals;"color&colon; &num;008000&semi;"><strong>binding&period;setPerson&lpar;user&rpar;&semi;<&sol;strong><&sol;span><&sol;pre>&NewLine;<h4 class&equals;"p1"><span style&equals;"color&colon; &num;0000ff&semi;"><strong>Binding Expressions<&sol;strong><&sol;span><&sol;h4>&NewLine;<p class&equals;"p1"><span style&equals;"color&colon; &num;008000&semi;"><strong>Binding expressions<&sol;strong><&sol;span> use a declarative language to define how a particular view interacts with bound objects&period;<&sol;p>&NewLine;<p class&equals;"p1">Expressions can&comma; for example&comma; include mathematical expressions&comma; method calls&comma; string concatenations&comma; access to array elements and comparison operations&period;<&sol;p>&NewLine;<p class&equals;"p1">A binding expression begins with an <span style&equals;"color&colon; &num;008000&semi;"><b>&commat;<&sol;b> <&sol;span>symbol followed by the expression enclosed in curly braces<span style&equals;"color&colon; &num;008000&semi;"><b> &lpar;&lbrace;&rcub;&rpar;<&sol;b><&sol;span>&period;<&sol;p>&NewLine;<p class&equals;"p1">Consider&comma; for example&comma; a <span style&equals;"color&colon; &num;008000&semi;"><b>User<&sol;b><&sol;span> instance containing variables named <span style&equals;"color&colon; &num;008000&semi;"><strong>age&comma; name&period;<&sol;strong><&sol;span> Assume that this class has been assigned to a variable named <span style&equals;"color&colon; &num;008000&semi;"><b>user<&sol;b><&sol;span> within the data binding layout file and needs to be bound to TextView objects&period; If this value was stored as a String object&comma; this would be declared within the layout file as follows&colon;<&sol;p>&NewLine;<pre>&lt&semi;&quest;xml version&equals;"1&period;0" encoding&equals;"utf-8"&quest;&gt&semi;&NewLine;&NewLine;&lt&semi;layout xmlns&colon;android&equals;"http&colon;&sol;&sol;schemas&period;android&period;com&sol;apk&sol;res&sol;android"&NewLine;xmlns&colon;app&equals;"http&colon;&sol;&sol;schemas&period;android&period;com&sol;apk&sol;res-auto"&NewLine;xmlns&colon;tools&equals;"http&colon;&sol;&sol;schemas&period;android&period;com&sol;tools"&gt&semi;&NewLine;&NewLine;&lt&semi;data&gt&semi;&NewLine;&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;"> &lt&semi;variable<&sol;span><&sol;strong>&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;"> name&equals;"user"<&sol;span><&sol;strong>&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;"> type&equals;"com&period;example&period;databindingdemo&period;User" &sol;&gt&semi;<&sol;span><&sol;strong>&NewLine;&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;"> &lt&semi;variable<&sol;span><&sol;strong>&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;"> name&equals;"handlers"<&sol;span><&sol;strong>&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;"> type&equals;"com&period;example&period;databindingdemo&period;MyHandler" &sol;&gt&semi;<&sol;span><&sol;strong>&NewLine;&NewLine;&lt&semi;&sol;data&gt&semi;&NewLine;&NewLine;&lt&semi;LinearLayout&NewLine; android&colon;layout&lowbar;width&equals;"match&lowbar;parent"&NewLine; android&colon;layout&lowbar;height&equals;"match&lowbar;parent"&NewLine; android&colon;orientation&equals;"vertical"&NewLine; android&colon;layout&lowbar;margin&equals;"50dp"&gt&semi;&NewLine;&NewLine; &lt&semi;TextView&NewLine; android&colon;layout&lowbar;width&equals;"wrap&lowbar;content"&NewLine; android&colon;layout&lowbar;height&equals;"wrap&lowbar;content"&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;">android&colon;text&equals;"&commat;&lbrace;user&period;name&rcub;"<&sol;span><&sol;strong> &sol;&gt&semi;&NewLine;&NewLine; &lt&semi;TextView&NewLine; android&colon;layout&lowbar;width&equals;"wrap&lowbar;content"&NewLine; android&colon;layout&lowbar;height&equals;"wrap&lowbar;content"&NewLine; <span style&equals;"color&colon; &num;008000&semi;"><strong>android&colon;text&equals;"&commat;&lbrace;user&period;age&rcub;"<&sol;strong><&sol;span> &sol;&gt&semi;&NewLine;&NewLine; &lt&semi;Button&NewLine; android&colon;layout&lowbar;width&equals;"wrap&lowbar;content"&NewLine; android&colon;layout&lowbar;height&equals;"wrap&lowbar;content"&NewLine; <strong><span style&equals;"color&colon; &num;008000&semi;">android&colon;onClick&equals;"&commat;&lbrace;handlers&colon;&colon;onButtonClick&rcub;"<&sol;span><&sol;strong>&NewLine; android&colon;text&equals;"CLICK" &sol;&gt&semi;&NewLine;&NewLine;&lt&semi;&sol;LinearLayout&gt&semi;&NewLine;&NewLine;&lt&semi;&sol;layout&gt&semi;<&sol;pre>&NewLine;<p class&equals;"p1"><span style&equals;"color&colon; &num;0000ff&semi;"><strong>String concatenation<&sol;strong><&sol;span><&sol;p>&NewLine;<p class&equals;"p1">String concatenation may also be used&period; For example&comma; to include the word<span style&equals;"color&colon; &num;008000&semi;"><strong> &OpenCurlyDoubleQuote;years”<&sol;strong><&sol;span> after the age value the following expression would be used&colon;<&sol;p>&NewLine;<pre class&equals;"p1">android&colon;text&equals;'&commat;&lbrace;user&period;age&plus;" years"&rcub;'<&sol;pre>&NewLine;<p class&equals;"p1"><span style&equals;"color&colon; &num;008000&semi;"><b><span style&equals;"color&colon; &num;0000ff&semi;">Note&colon;<&sol;span> Since the appended string is wrapped in double-quotes&comma; the expression is now encapsulated with single quotes to avoid syntax errors&period;<&sol;b><&sol;span><&sol;p>&NewLine;<p><span style&equals;"color&colon; &num;0000ff&semi;"><strong>ternary statements<&sol;strong><&sol;span><&sol;p>&NewLine;<p class&equals;"p1">The expression syntax also allows ternary statements to be declared&period; In the following expression&comma; we are setting the visibility of a view to <strong><span style&equals;"color&colon; &num;0000ff&semi;">GONE<&sol;span><&sol;strong> or <strong><span style&equals;"color&colon; &num;0000ff&semi;">VISIBLE<&sol;span><&sol;strong> depending on the value of age&period;<&sol;p>&NewLine;<pre class&equals;"p1">android&colon;visibility&equals;"&commat;&lbrace;user&period;age &gt&semi; 13 &quest; View&period;GONE &colon; View&period;VISIBLE&rcub;"<&sol;pre>&NewLine;<p class&equals;"p1">Expressions may also be constructed to access specific elements in a data array&colon;<&sol;p>&NewLine;<pre class&equals;"p1">&commat;&lbrace;user&period;nameArray&lbrack;3&rsqb;&rcub;<&sol;pre>&NewLine;<p class&equals;"p1">A binding expression on a Button&comma; for example&comma; might declare which method on an object is called in response to a click&period;<&sol;p>&NewLine;<pre class&equals;"p1">&lt&semi;Button&NewLine;&NewLine;<span class&equals;"Apple-converted-space">    <&sol;span>android&colon;layout&lowbar;width&equals;"wrap&lowbar;content"&NewLine;&NewLine;<span class&equals;"Apple-converted-space">    <&sol;span>android&colon;layout&lowbar;height&equals;"wrap&lowbar;content"&NewLine;&NewLine;<span class&equals;"Apple-converted-space">    <&sol;span><span style&equals;"color&colon; &num;008000&semi;"><strong>android&colon;onClick&equals;"&commat;&lbrace;handlers&colon;&colon;onButtonClick&rcub;"<&sol;strong><&sol;span>&NewLine;&NewLine;<span class&equals;"Apple-converted-space">    <&sol;span>android&colon;text&equals;"CLICK" &sol;&gt&semi;<&sol;pre>&NewLine;<p class&equals;"p1">Binding expressions provide a rich and flexible language in which to bind user interface views to data and methods in other objects and this article has only covered the most common use cases&period; To learn more about binding expressions&comma; review the Android <span style&equals;"color&colon; &num;0000ff&semi;"><strong><a style&equals;"color&colon; &num;0000ff&semi;" href&equals;"https&colon;&sol;&sol;developer&period;android&period;com&sol;topic&sol;libraries&sol;data-binding&sol;expressions">documentation<&sol;a><&sol;strong><&sol;span>&period;<&sol;p>&NewLine;<h4 class&equals;"p1"><span style&equals;"color&colon; &num;0000ff&semi;"><strong>Event and Listener Bindings<&sol;strong><&sol;span><&sol;h4>&NewLine;<p class&equals;"p1">Not just the data&comma; we can also bind the click and other events on UI elements&period; To bind a click event&comma; you need to create a class with necessary callback methods&period;<&sol;p>&NewLine;<p class&equals;"p1">Below we have a class that handles the button click event&period;<&sol;p>&NewLine;<pre class&equals;"p1">public class MyClickHandlers &lbrace;&NewLine;&NewLine;<span class&equals;"Apple-converted-space">    <&sol;span>public void onButtonClicked&lpar;View view&rpar; &lbrace;&NewLine;&NewLine;<span class&equals;"Apple-converted-space">        <&sol;span>Toast&period;makeText&lpar;getApplicationContext&lpar;&rpar;&comma; "button clicked&excl;"&comma; Toast&period;LENGTH&lowbar;SHORT&rpar;&period;show&lpar;&rpar;&semi;&NewLine;<span class&equals;"Apple-converted-space">    <&sol;span>&rcub;&NewLine;&rcub;<&sol;pre>&NewLine;<p class&equals;"p1">To bind the event&comma; we use the same <span style&equals;"color&colon; &num;008000&semi;"><b>&lt&semi;variable&gt&semi;<&sol;b><&sol;span> tag with the path to <span style&equals;"color&colon; &num;008000&semi;"><strong>handler<&sol;strong><&sol;span> class&period; Below <span style&equals;"color&colon; &num;0000ff&semi;"><b>android&colon;onClick&equals;”&commat;&lbrace;handlers&colon;&colon;onButtonClicked&rcub;”<&sol;b><&sol;span> binds the button click to <span style&equals;"color&colon; &num;0000ff&semi;"><b>onButtonClicked&lpar;&rpar;<&sol;b><&sol;span> method&period;<&sol;p>&NewLine;<div id&equals;"paste-embed-wrapper">&NewLine;<pre>&lt&semi;&quest;xml version&equals;"1&period;0" encoding&equals;"utf-8"&quest;&gt&semi;&NewLine;&NewLine;&lt&semi;layout xmlns&colon;android&equals;"http&colon;&sol;&sol;schemas&period;android&period;com&sol;apk&sol;res&sol;android"&gt&semi;&NewLine;&NewLine;&lt&semi;data&gt&semi;&NewLine;&NewLine; <span style&equals;"color&colon; &num;008000&semi;"><strong>&lt&semi;variable<&sol;strong><&sol;span>&NewLine;<span style&equals;"color&colon; &num;008000&semi;"><strong> name&equals;"handlers"<&sol;strong><&sol;span>&NewLine;<span style&equals;"color&colon; &num;008000&semi;"><strong> type&equals;"com&period;example&period;databindingdemo&period;MyClickHandlers" &sol;&gt&semi;<&sol;strong><&sol;span>&NewLine;&lt&semi;&sol;data&gt&semi;&NewLine;&NewLine;&lt&semi;RelativeLayout &period;&period;&period;&gt&semi;&NewLine;&NewLine;&lt&semi;Button&NewLine;&period;&period;&period;&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;">android&colon;onClick&equals;"&commat;&lbrace;handlers&colon;&colon;onButtonClicked&rcub;"<&sol;span><&sol;strong> &sol;&gt&semi;&NewLine;&NewLine;&lt&semi;&sol;RelativeLayout&gt&semi;&NewLine;&NewLine;&lt&semi;&sol;layout&gt&semi;<&sol;pre>&NewLine;<&sol;div>&NewLine;<p class&equals;"p1">Another option&comma; and one which provides the ability to pass parameters to the method&comma; is referred to as a <span style&equals;"color&colon; &num;0000ff&semi;"><b>listener<&sol;b><&sol;span> binding&period; The following expression uses this approach to call a method on the same <strong><span style&equals;"color&colon; &num;008000&semi;">handlers<&sol;span><&sol;strong> instance with no parameters&colon;<&sol;p>&NewLine;<pre class&equals;"p1">android&colon;onClick&equals;'&commat;&lbrace;&lpar;&rpar; -&gt&semi; handlers&period;methodOne&lpar;&rpar;&rcub;'<&sol;pre>&NewLine;<p class&equals;"p1">The following expression calls a method that expects three parameters&colon;<&sol;p>&NewLine;<pre class&equals;"p1">android&colon;onClick&equals;'&commat;&lbrace;&lpar;&rpar; -&gt&semi; handlers&period;methodTwo&lpar;user&period;name&comma; 10&comma; "A String"&rpar;&rcub;'<&sol;pre>&NewLine;<p>To bind the events&comma; <span style&equals;"color&colon; &num;008000&semi;"><b>binding&period;setHandlers&lpar;handlers&rpar;<&sol;b><&sol;span> is called from the activity&period;<&sol;p>&NewLine;<h3><span style&equals;"color&colon; &num;000080&semi;"><strong>Data Binding Basic Example<&sol;strong><&sol;span><&sol;h3>&NewLine;<p>Let’s say we want to display user information from a <strong><span style&equals;"color&colon; &num;008000&semi;">User<&sol;span><&sol;strong> POJO class&period; We generally display the info in a TextView using <strong><span style&equals;"color&colon; &num;008000&semi;">setText&lpar;&rpar; <&sol;span><&sol;strong>method&period; But instead of manually calling setText for each user property&comma; DataBinding allows us to bind the values automatically&period;<&sol;p>&NewLine;<p>The below POJO class creates an <span style&equals;"color&colon; &num;0000ff&semi;"><strong>User<&sol;strong><&sol;span> object with <strong><span style&equals;"color&colon; &num;008000&semi;">firstName<&sol;span><&sol;strong> and <strong><span style&equals;"color&colon; &num;008000&semi;">lastName <&sol;span><&sol;strong><span style&equals;"color&colon; &num;000000&semi;">fields&period;<&sol;span><&sol;p>&NewLine;<pre>public class User &lbrace;&NewLine;&NewLine;public final String firstName&semi;&NewLine;&NewLine;public final String lastName&semi;&NewLine;&NewLine;public User&lpar;String firstName&comma; String lastName&rpar; &lbrace;&NewLine;this&period;firstName &equals; firstName&semi;&NewLine;this&period;lastName &equals; lastName&semi;&NewLine;&rcub;&NewLine;&rcub;<&sol;pre>&NewLine;<p><span style&equals;"color&colon; &num;000080&semi;"><strong>Data binding layout file<&sol;strong><&sol;span><&sol;p>&NewLine;<ul>&NewLine;<li>To enable DataBinding in a layout&comma; the root element should start with <span style&equals;"color&colon; &num;0000ff&semi;"><strong>&lt&semi;layout&gt&semi; <&sol;strong><&sol;span>tag followed by <strong><span style&equals;"color&colon; &num;0000ff&semi;">&lt&semi;data&gt&semi;<&sol;span><&sol;strong> tag&period;<&sol;li>&NewLine;<li>Inside &lt&semi;data&gt&semi; tag&comma;  a <strong><span style&equals;"color&colon; &num;0000ff&semi;">&lt&semi;variable&gt&semi;<&sol;span><&sol;strong> tag takes two attributes &grave;name&grave; and &grave;type&grave;&period; <strong><span style&equals;"color&colon; &num;008000&semi;">name<&sol;span><&sol;strong> attribute will be alias name and type should be of object model class&period;<&sol;li>&NewLine;<li>To bind a value&comma; &commat; annotation should be used&period; In the below layout&comma; user <strong><span style&equals;"color&colon; &num;008000&semi;">firstName<&sol;span><&sol;strong> and <strong><span style&equals;"color&colon; &num;008000&semi;">lastName<&sol;span><&sol;strong> are bound to TextView using <span style&equals;"color&colon; &num;008000&semi;"><strong>&commat;&lbrace;user&period;firstName&rcub;<&sol;strong><&sol;span> and <strong><span style&equals;"color&colon; &num;008000&semi;">&commat;&lbrace;user&period;lastName&rcub;<&sol;span><&sol;strong>&period;<&sol;li>&NewLine;<&sol;ul>&NewLine;<pre>&lt&semi;&quest;xml version&equals;"1&period;0" encoding&equals;"utf-8"&quest;&gt&semi;&NewLine;&NewLine;&lt&semi;layout xmlns&colon;android&equals;"http&colon;&sol;&sol;schemas&period;android&period;com&sol;apk&sol;res&sol;android"&NewLine;&NewLine;   xmlns&colon;app&equals;"http&colon;&sol;&sol;schemas&period;android&period;com&sol;apk&sol;res-auto"&gt&semi;&NewLine;&NewLine;    &lt&semi;data&gt&semi;&NewLine;&NewLine;       &lt&semi;variable&NewLine;&NewLine;            <strong><span style&equals;"color&colon; &num;0000ff&semi;">name<&sol;span><&sol;strong>&equals;"user"&NewLine;&NewLine;            <strong><span style&equals;"color&colon; &num;0000ff&semi;">type<&sol;span><&sol;strong>&equals;"com&period;example&period;databindingdemo&period;User" &sol;&gt&semi;&NewLine;&NewLine;    &lt&semi;&sol;data&gt&semi;&NewLine;&NewLine;  &lt&semi;LinearLayout&NewLine;&NewLine;      android&colon;layout&lowbar;width&equals;"match&lowbar;parent"&NewLine;&NewLine;      android&colon;layout&lowbar;height&equals;"match&lowbar;parent"&NewLine;&NewLine;      android&colon;orientation&equals;"vertical"&NewLine;&NewLine;      android&colon;layout&lowbar;margin&equals;"50dp"&gt&semi;&NewLine;&NewLine;&NewLine;      &lt&semi;TextView&NewLine;&NewLine;          android&colon;layout&lowbar;width&equals;"match&lowbar;parent"&NewLine;&NewLine;          android&colon;layout&lowbar;height&equals;"wrap&lowbar;content"&NewLine;&NewLine;          android&colon;textSize&equals;"25sp"&NewLine;&NewLine;          <strong><span style&equals;"color&colon; &num;008000&semi;">android&colon;text&equals;"&commat;&lbrace;user&period;firstName&rcub;"<&sol;span><&sol;strong>&sol;&gt&semi;&NewLine;&NewLine;&NewLine;      &lt&semi;TextView&NewLine;&NewLine;          android&colon;layout&lowbar;width&equals;"match&lowbar;parent"&NewLine;&NewLine;          android&colon;layout&lowbar;height&equals;"wrap&lowbar;content"&NewLine;&NewLine;          android&colon;textSize&equals;"25sp"&NewLine;&NewLine;          android&colon;layout&lowbar;marginTop&equals;"15dp"&NewLine;&NewLine;         <span style&equals;"color&colon; &num;008000&semi;"><strong> android&colon;text&equals;"&commat;&lbrace;user&period;lastName&rcub;"<&sol;strong><&sol;span>&sol;&gt&semi;&NewLine;&NewLine;  &lt&semi;&sol;LinearLayout&gt&semi;&NewLine;&NewLine;&lt&semi;&sol;layout&gt&semi;<&sol;pre>&NewLine;<ul>&NewLine;<li> The expression <span style&equals;"color&colon; &num;008000&semi;"><strong>&commat;&lbrace;user&period;firstName&rcub;<&sol;strong><&sol;span> used for the <span style&equals;"color&colon; &num;0000ff&semi;"><strong>android&colon;text<&sol;strong><&sol;span> attribute accesses the <span style&equals;"color&colon; &num;008000&semi;"><strong>firstName<&sol;strong><&sol;span> field in the former class&period;<&sol;li>&NewLine;<li>The generated binding classes follow the naming convention considering the layout file name in which binding is enabled&period; For the layout <strong><span style&equals;"color&colon; &num;008000&semi;">activity&lowbar;main&period;xml<&sol;span><&sol;strong>&comma; the generated binding class will be <strong><span style&equals;"color&colon; &num;008000&semi;">ActivityMainBinding<&sol;span><&sol;strong> &lpar;Binding suffix will be added at the end&rpar;&period;<&sol;li>&NewLine;<&sol;ul>&NewLine;<p><span style&equals;"color&colon; &num;000080&semi;"><strong>Creating a Binding object<&sol;strong><&sol;span><&sol;p>&NewLine;<ul>&NewLine;<li>To bind the data in UI&comma; you need to inflate the binding layout first using the generated binding classes&period; Below&comma; <strong><span style&equals;"color&colon; &num;008000&semi;">ActivityMainBinding<&sol;span><&sol;strong> inflates the layout first and <strong><span style&equals;"color&colon; &num;008000&semi;">binding&period;setUser&lpar;&rpar;<&sol;span><&sol;strong> binds the <strong><span style&equals;"color&colon; &num;0000ff&semi;">User<&sol;span><&sol;strong> object to the layout&period;<br &sol;>&NewLine;<strong><span style&equals;"color&colon; &num;0000ff&semi;">You can notice here&comma; we haven’t used findViewById&lpar;&rpar; anywhere&period;<&sol;span><&sol;strong><&sol;li>&NewLine;<&sol;ul>&NewLine;<pre>public class MainActivity extends AppCompatActivity &lbrace;&NewLine;&NewLine;ActivityMainBinding binding&semi;&NewLine;&NewLine;&commat;Override&NewLine;protected void onCreate&lpar;Bundle savedInstanceState&rpar; &lbrace;&NewLine;super&period;onCreate&lpar;savedInstanceState&rpar;&semi;&NewLine;<strong><span style&equals;"color&colon; &num;008000&semi;">&sol;&sol; setContentView&lpar;R&period;layout&period;activity&lowbar;main&rpar;&semi;<&sol;span><&sol;strong>&NewLine;&NewLine;binding &equals; DataBindingUtil&period;setContentView&lpar;this&comma;R&period;layout&period;activity&lowbar;main&rpar;&semi;&NewLine;&NewLine;User user&equals; new User&lpar;"Arun"&comma;"Chandravanshi"&rpar;&semi;&NewLine;<span style&equals;"color&colon; &num;008000&semi;"><strong>binding&period;setUser&lpar;user&rpar;&semi;<&sol;strong><&sol;span>&NewLine;&rcub;&NewLine;&rcub;<&sol;pre>&NewLine;<p>If you run the app&comma; you can see the user details displayed in TextViews&period;<&sol;p>&NewLine;<p><img class&equals;" wp-image-1575 aligncenter" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2020&sol;02&sol;Screenshot&lowbar;1581756944&period;png" alt&equals;"Screenshot&lowbar;1581756944" width&equals;"518" height&equals;"292" &sol;><&sol;p>&NewLine;<p class&equals;"p1">That&&num;8217&semi;s all for this article&period; In the next <span style&equals;"color&colon; &num;0000ff&semi;"><strong><a style&equals;"color&colon; &num;0000ff&semi;" href&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;android-data-binding-in-recyclerview&sol;">article<&sol;a><&sol;strong><&sol;span>&comma; we will talk about how to implement <span style&equals;"color&colon; &num;008000&semi;"><b>recyclerView<&sol;b><&sol;span> in our app using <span style&equals;"color&colon; &num;008000&semi;"><strong>Data Binding<&sol;strong><&sol;span> library&period;&NewLine;

Exit mobile version