Home > Mobile >  why do inflate and root warn me?
why do inflate and root warn me?

Time:02-26

class MainActivity : AppCompatActivity() { 

    lateinit var binding: ActivityMainBinding 
    
    override fun onCreate(savedInstanceState: Bundle?) { 
        super.onCreate(savedInstanceState) 
        binding = ActivityMainBinding.inflate(layoutInflater, AppCompatActivity(),true)
        setContentView(binding.root) 
    }

CodePudding user response:

Try to inflate your layout with ActivityMainBinding.inflate(layoutInflater) and make the binding variable private:

class MainActivity : AppCompatActivity() { 

    private lateinit var binding: ActivityMainBinding 
    
    override fun onCreate(savedInstanceState: Bundle?) { 
        super.onCreate(savedInstanceState) 
        binding = ActivityMainBinding.inflate(layoutInflater) 
        setContentView(binding.root) 
    }
  • Related