Search code examples
javaandroiddata-bindingandroid-databinding2-way-object-databinding

How to import BR class while implementing two way data binding? Importing BR shows error in my code


I am inheriting BaseObservable class. In 'notifyPropertyChanged' method when i am passing integer fieldId, 'BR' class shows red error. I am trying to implement two-way data binding.

ViewModel.java

package com.example.test;

import android.databinding.BaseObservable;
import android.databinding.Bindable;

public class ViewModel extends BaseObservable {
String username;
String password;

@Bindable
public String getUsername() {
    return username;
}
public void setUsername(String username) {
    this.username = username;
    notifyPropertyChanged(BR.username);
}
@Bindable
public String getPassword() {
    return password;
}

public void setPassword(String password) {
    this.password = password;
    notifyPropertyChanged(BR.password);
}
}

Solution

  • I have found the problem. The problem is in the latest version of IDE i.e. Android Studio 3.3 . It's working fine in version 3.2.1 . I hope that Google resolves this issue soon.