In my simple application i would like to change one image view url by clicking on button after setting default url into that, for example in imageView i have google logo image and after clicking on button that updating to image stackoverflow logo

unfortunately my implemented code for BindingAdapter that only work once when i run application,showing google logo image and after changing image url and using notifyPropertyChanged that doesn't work

ImageBindingAdapter class:

object ImageBindingAdapter {
    @BindingAdapter("imageUrl", "placeholder", requireAll = false)
    fun loadImage(imageView: ImageView, imageUrl: String, placeholder: Drawable) {
        if (imageUrl != "") {

my User class which that have image url

class User : BaseObservable() {
    var username: String? = null
    var password: String? = null
    var profilePicUrl: String? = null
        set(profilePicUrl) {
            field = profilePicUrl

and then my LoginActivity

override fun onCreate(savedInstanceState: Bundle?) {
    val binding: LoginActivityBinding = DataBindingUtil.setContentView(this, R.layout.login_activity)
    binding.viewModel = ViewModelProviders.of(this, LoginViewModelFactory(this)).get(

    val user = User()
    user.username = "xxxx"
    user.password = "xxxxxxxxxx"
    user.profilePicUrl = ""

    binding.user = user

    val handlers = ClickHandler()
    handlers.user = user
    binding.handlers = handlers


ClickHandler class:

class ClickHandler {
    var user: User? = null

    fun clickOnLoginButton(view: View) {
        user?.profilePicUrl = ""

TIP: this ClickHandler after multiple clicking on that work fine, i tested

layout xml

    ... />

    ... />

0 Answers