t Google I/O 2015 numerous new android developer libraries and tools were introduced. One of these was the brand new Data Binding library as well as in this series we’ll check out the library and explore a few of the effective features it offers.
The following factor that we’ll turn our focus on is really altering other facets of the Sights within out layout. To facilitate this we’ll introduce new things within our data model. The Twitter API includes the idea of cited tweets – where one user quotes another person’s tweet which are incorporated within the twitter4j.Status object being an child twitter4j.Status object which signifies the tweet being cited.
This really is really quite simple – we assess the hasQuotedStatus() method which we simply defined, and employ a ternary expression to create the visibility accordingly. The Information Binding library doesn’t unconditionally know of the constants defined within the View class, so we have to import it to supply that visibility. This really is roughly equal to a Java import.
I’d explain that I am not an enormous fan of utilizing ternary expressions in this manner because they’ll be much trickier to debug. Personally I’d be incorporated to utilize a custom setter to really implement the conditional logic (upon which you’ll set a breakpoint). However, within the interests of showing more particulars from the expression language I have tried personally ternary expression within the example code.
The following factor we are able to do is then add event handling – the written text android developer put into the placeholder box for that cited status states “Tap to load tweet” so we’re clearly likely to beed some click handling logic. Once more we are able to do that through Data Binding .
When we run this we are able to observe that only a few tweets display the cited tweet container, and when we tap on a single we obtain the Snackbar message appear – so our both conditional display logic and our click handling will work:
The key factor this click handling provides for us is we have a mention of Data being certain to when we’re processing the press event which is an essential part of the MVVM pattern since it provides for us to change the ModelView at this time. We’ll cover why that’s helpful within the next article.