Wiring up the UI with the Java code (part 1)
To achieve an interactive app, we will do three things:
We will call
setContentView
from theonCreate
method to show the progress of our UI when we run the appWe will write two more methods 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 methods loadConstraintLayout
and loadTableLayout
, respectively.
Let's do that now, and then we can see how we can add some buttons that call these methods alongside some neatly formatted text.
Inside the onCreate
method, add the following highlighted code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_menu);
}
The code uses the setContentView
method to load the UI we are currently...