Changes

Jump to: navigation, search

Kotlin - Android Activity State Changes by Example

180 bytes added, 16:21, 24 November 2017
no edit summary
The next action to take involves the design of the content area of the user interface for the activity. This is stored in a file named content_state_change.xml which should already be loaded into the Layout Editor tool. If it is not, navigate to it in the project tool window where it can be found in the app -> res -> layout folder. Once located, double-clicking on the file will load it into the Android Studio Layout Editor tool.
[[File:as3.0_kotlin_state_change_main.png]]
== Designing the User Interface ==
From the Palette located on the left side of the Layout Editor, select the Text category and, from the list of text components, click and drag a Plain Text component over to the visual representation of the device screen. Move the component to the center of the display so that the center guidelines appear and drop it into place so that the layout resembles that of Figure 20-2.
[[File:as3.0_statechange_ui.png]]
When using the EditText widget it is necessary to specify an input type for the view. This simply defines the type of text or data that will be entered by the user. For example, if the input type is set to Phone, the user will be restricted to entering numerical digits into the view. Alternatively, if the input type is set to TextCapCharacters, the input will default to upper case characters. Input type settings may also be combined.
Display the Logcat tool window and click on the filter menu (marked as B in Figure 20-3) to review the available options. When this menu is set to Show only selected application, only those messages relating to the app selected in the menu marked as A will be displayed in the Logcat panel. Choosing No Filter, on the other hand, will display all the messages generated by the device or emulator.
[[File:as3.0_statechange_filter.png]]
From the filter menu (B), select the Edit Filter Configuration menu option. In the Create New Logcat Filter dialog (Figure 20-4), name the filter Lifecycle and, in the Log Tag field, enter the Tag value declared in StateChangeActivity.kt (in the above code example this was StateChange).
[[File:as3.0_statechange_filter_dialog.png]]
Enter the package identifier in the Package Name field (clicking on the search icon in the text field will drop down a menu from which the package name may be selected) and, when the changes are complete, click on the OK button to create the filter and dismiss the dialog. Instead of listing No Filters, the newly created filter should now be selected in the Logcat tool window.
[[File:as_3.0_run_button.png]]
A review of the Logcat panel should indicate which methods have so far been triggered (taking care to ensure that the Lifecycle filter created in the preceding section is selected to filter out log events that are not currently of interest to us):
[[File:as3.0_statechange_filtered_results.png]]
== Experimenting with the Activity ==

Navigation menu