Book Image

Android Studio 3.5 Development Essentials - Java Edition

By : Neil Smyth
Book Image

Android Studio 3.5 Development Essentials - Java Edition

By: Neil Smyth

Overview of this book

Android applications have become an important part of our daily lives and lots of effort goes into developing an Android application. This book will help you to build you own Android applications using Java. Android Studio 3.5 Development Essentials – Java Edition first teaches you to install Android development and test environment on different operating systems. Next, you will create an Android app and a virtual device in Android Studio, and install an Android application on emulator. You will test apps on physical Android devices, then study Android Studio code editor and constraint layout, Android architecture, the anatomy of an Android app, and Android activity state changes. The book then covers advanced topics such as views and widgets implementation, multi-window support integration, and biometric authentication, and finally, you will learn to upload your app to Google Play console and handle the build process with Gradle. By the end of this book, you will have gained enough knowledge to develop powerful Android applications using Java.
Table of Contents (86 chapters)
86
Index

22.2 Creating Views

As previously established, the Android SDK includes a toolbox of view classes designed to meet most of the basic user interface design needs. The creation of a view in Java is simply a matter of creating instances of these classes, passing through as an argument a reference to the activity with which that view is to be associated.

The first view (typically a container view to which additional child views can be added) is displayed to the user via a call to the setContentView() method of the activity. Additional views may be added to the root view via calls to the object’s addView() method.

When working with Java code to manipulate views contained in XML layout resource files, it is necessary to obtain the ID of the view. The same rule holds true for views created in Java. As such, it is necessary to assign an ID to any view for which certain types of access will be required in subsequent Java code. This is achieved via a call to the setId() method of...