简体   繁体   中英

Consolidating setContentView(R.layout.activity_main) with ViewBinding

I'm fairly new to Android development and i'm trying to combine the functionality from 2 separate tutorials into one app.

One of them, which i've already implemented, simply uses setContentView(R.layout.activity_main) in order to provide the main activity for it's fragments. The second uses the below code

binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
setSupportActionBar(binding.toolbar)

What is the best way for me to go about combining these 2 different approaches so i don't end up creating errors in the code already implemented. And will it be necessary to convert all existing fragments to 'data binding layout' as a result?

Thanks

You can use both of them together, no necessary to convert all the existing fragment to 'data binding layout', I also have something of this in one of my projects.

The best way to proceed is to start the new Activity/Fragment with view binding and with overtime you can one class at a time update existing Activity/Fragment to avoid too many of changes in one go.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM