Search code examples
androiddata-bindingandroid-databinding

Databinding BR not working in my mvvm project in notifyPropertyChanged method


I'm trying to learn mvvm with a simple project but BR not working for me. I import com.example.mvvm.BR to my class but android studio show me cannot resolve symbol BR.

public class UserViewModel extends BaseObservable
{
    private String name;

    private Context context;

    public UserViewModel(User user)
    {
        this.name = name;
    }

    public UserViewModel(Context context)
    {
        this.context = context;
    }

    @Bindable
    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
        notifyPropertyChanged(BR.name);//error 
    }
}

What should I do?


Solution

  • The BR file is generated when the project is build. And will be cleared if you clean the project or any error occur during building the project. Try rebuilding the project. Build -> Rebuild Project. If there are no other errors and build is successful, then the BR will be resolved.