Can't resolve Android databinding class

前端 未结 23 2220
南旧
南旧 2020-12-02 19:55

While using data binding , I am not able to get class MainActivityBinding as per Data Binding Guide

My layout name is activity_main.xml. I

23条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-02 20:28

    Thanks to all for your answer.I found solution with ContentMainBinding class name for data binding. Lets me explain.

    NOTE: While using layout with here is having Data Binding functionality, the class name related to include layout name. Here is the ContentMainBinding

    My layout file are as below:

    activity_main.xml

    
    
        ...
        
        ...
        
    

    And content_main.xml is layout where I added my Data Binding layout code.

    So instead of using MainActivityBinding it can resolved with ContentMainBinding

    The code which work for me is below:

    //Code for data binding
        ContentMainBinding contentMainBinding = DataBindingUtil.setContentView(this, R.layout.content_main);
        user = new User("Pranay", "Patel", "demoemail@gmail.com", "9999999999");
        contentMainBinding.setUser(user);
    

    DONE.

提交回复
热议问题