DataBindingUtil not found in my mainActivity

Viewed 4335

I'm adding in my gradle

buildFeatures {
    viewBinding true
} 
public class MainActivity3 extends AppCompatActivity {
    ActivityMain3Binding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityMain3Binding.inflate(getLayoutInflater());

        binding=DataBindingUtil // don't found 

        View view = binding.getRoot();
        setContentView(view);

        binding.EdName.setText("test text");
    }

I need help or good and new tutorial to understand dataBinding

3 Answers

You also need to enable data binding in your app-level build.gradle:

android {
    ...
    buildFeatures {
        dataBinding true
        viewBinding true
    }
}

1-In your app’s build.gradle set data binding as usual

2-Add the compiler dependency

3- Then apply the plugin at the top of the file:

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-kapt'

android {
    buildFeatures {
     dataBinding true
   }
}

dependencies {
    kapt "com.android.databinding:compiler:3.0.1"
}

You also need to enable data binding in build.gradle

buildFeatures { dataBinding true viewBinding true }

Related