-
-
Save albodelu/862d85e7040ce1d78fc1151e9f5bbe3c to your computer and use it in GitHub Desktop.
Binding Adapters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //forma clásica extrapolada directamente de java | |
| //funcion estatica donde el primer parámetro es la vista y los n siguientes los especificados por le BindingAdapter | |
| @BindingAdapter("bind:url") | |
| fun loadUrl(imageView: ImageView, url: String) { | |
| Picasso.with(imageView.ctx).load(url).transform(CircleTransform()).into(imageView) | |
| } | |
| //opción alternativa | |
| @BindingAdapter("bind:url") | |
| fun ImageView.loadUrl(url: String) { | |
| Picasso.with(this.ctx).load(url).transform(CircleTransform()).into(this) | |
| } | |
| /*Nótese que segun el compilador ambas funciones tienen la misma signature por lo que no podrán estar definidas a la vez*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| imageView.loadUrl("url_de_la_imagen") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <ImageView ... | |
| bind:url='@{"url_de_la_imagen"}' | |
| /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment