How to use View Binding in Android

View Binding

Step1 : First go to build.gradle Module

Place below code inside android{ }

   buildFeatures{
        viewBinding true
    }


Now Click on Sync now 
Step2 :  In Activity java class you just type
           Activity you will get the Activity name Select it . 
          like if we have MainActivity 
        

        
       ActivityMainActivityBinding binding;


       binding = ActivityMainActivityBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());


Example :

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

        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setTitle("Shooping cart");

        binding.checkoutBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                Toast.makeText(Add_To_Cart.this, "Payment is success", Toast.LENGTH_SHORT).show();
                Intent intent = new Intent(Add_To_Cart.this, Checkout_Sprintkart.class);
                startActivity(intent);
                finish();



            }
        });

    }