Wiring up the UI with the Kotlin code (part 1)
To achieve an interactive app, we will do the following three things:
We will call
setContentView
from theonCreate
function to show the progress of our UI when we run the app.We will write two more functions of our own and each one will call
setContentView
on a different layout (that we have yet to design).Then, later in this chapter, when we design two more UI layouts, we will be able to load them at the click of a button.
As we will be building a ConstraintLayout
and a TableLayout
, we will call our new functions, loadConstraintLayout
and loadTableLayout
, respectively.
Let's do that now, and then we'll see how we can add some buttons that call these functions alongside some neatly formatted text.
Inside the onCreate
function, add the following highlighted code:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main_menu)
}
The code uses the setContentView
function to load...