Coder Social home page Coder Social logo

ndaedzophoshoko / databinding-viewbinding Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 104 KB

Data Binding defines a strategy that efficiently connects the UI and the code data. Whereas View Binding connects UI views and the source code. Both this strategies are effective and reduce system processing time.

Java 100.00%

databinding-viewbinding's Introduction

Data Binding with View Binding

Documentation here

Data Binding https://developer.android.com/topic/libraries/data-binding
View Binding https://developer.android.com/topic/libraries/view-binding#java

Note that this strategy is effective as it reduces the processing time. This style does not advise the use of the old approach of referencing views using the famous findViewById() method.

Approach steps

Step 1 Add the below configuration in the gradle.build module -> android tag

Screenshot (279)

Step 2 Design your UI layout file, assuming takes the name activity_main.xml, include the root element into the layout element, for data binding also include the data element with the variable name and type, the type refers to the class the raw data belongs to (model), see below

pic2

Step 3 Now the system auto-generates a binding class corresponding to the name of your UI layout file. Mine is ActivityMainBinding, so in MainActivity.java, I'll declare the instance of this ActivityMainBinding class. Then we need to connect the inflated layout and the binding utility from this activity

pic4

Step 4 We are done, we just use the binding instance to help us access all the data and views without using the ID or any help of findViewById()

Make sure that you follow me on Linkedin.com, here Ndaedzo Phoshoko (FullStack Developer path). Note Views will not be onbind if you do not give them IDs, so take note of this whenever you perform binding for your data with views.

See my example below

ViewBindingAndDataBinding-ezgif com-video-to-gif-converter

databinding-viewbinding's People

Contributors

ndaedzophoshoko avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.