Android Studio Giraffe Essentials - Kotlin Edition by Neil Smyth
Author:Neil Smyth
Language: eng
Format: epub
Publisher: Payload Media, Inc.
Published: 2023-08-11T19:02:10+00:00
action.message = binding.userText.text.toString()
Navigation.findNavController(it).navigate(action)
}
The above code obtains a reference to the action object, sets the message argument string using the setMessage() method, and then calls the navigate() method of the navigation controller, passing through the action object. If Android Studio reports FirstFragmentDirections as undefined, rebuild the project using the Build -> Make Project menu option to generate the class.
All that remains is to modify the SecondFragment.kt class file to receive the argument after the navigation has been performed and display it on the TextView widget. For this example, the code to achieve these tasks will be added using an onStart() lifecycle method. Edit the SecondFragment.kt file and add this method so that it reads as follows:
override fun onStart() {
super.onStart()
arguments?.let {
val args = SecondFragmentArgs.fromBundle(it)
binding.argText.text = args.message
}
}
The code in the above method begins by obtaining a reference to the TextView widget. Next, the fromBundle() method of the SecondFragmentArgs class is called to extract the SecondFragmentArgs object received from the origin. Since the argument in this example was named message in the navigation_graph.xml file, the corresponding getMessage() method is called on the args object to obtain the string value. This string is then displayed on the TextView widget.
Compile and run the app and enter some text before clicking on the Button widget. When the second fragment destination appears, the TextView should display the text entered in the first fragment, indicating that the data was successfully passed between navigation destinations.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Practical Guide to Azure Cognitive Services by Chris Seferlis & Christopher Nellis & Andy Roberts(6273)
Unity Artificial Intelligence Programming - Fifth Edition by Dr. Davide Aversa(5865)
Serverless ETL and Analytics with AWS Glue by Vishal Pathak Subramanya Vajiraya Noritaka Sekiyama Tomohiro Tanaka Albert Quiroga Ishan Gaur(4868)
Open Source Projects - Beyond Code by John Mertic(3947)
The AI Product Manager's Handbook by Irene Bratsis(3909)
Graph Data Modeling in Python by Gary Hutson and Matt Jackson(3897)
Cloud Auditing Best Practices by Shinesa Cambric & Michael Ratemo(3543)
Aligning Security Operations with the MITRE ATT&CK Framework by Rebecca Blair(3518)
Graph Data Processing with Cypher by Anthapu Ravindranatha;(1709)
Data Literacy in Practice - A complete guide to data literacy and making smarter decisions with data through intelligent actions (2022) by Packt(1696)
Serverless Machine Learning with Amazon Redshift ML: Create, train, and deploy machine learning models using familiar SQL commands by Debu Panda Phil Bates Bhanu Pittampally Sumeet Joshi(1582)
Network Automation with Go by Nicolas Leiva & Michael Kashin(1535)
Unreal Engine 5 Game Development with C++ Scripting by Zhenyu George Li(1340)
Applied Machine Learning and High-Performance Computing on AWS by Mani Khanuja | Farooq Sabir | Shreyas Subramanian | Trenton Potgieter(1314)
Data Literacy in Practice by Angelika Klidas Kevin Hanegan(1311)
Graph Data Processing with Cypher by Ravindranatha Anthapu(1298)
Implementing Multifactor Authentication: Protect your applications from cyberattacks with the help of MFA by Marco Fanti(1200)
Fuzzing Against the Machine: Automate vulnerability research with emulated IoT devices on QEMU by Antonio Nappa Eduardo Blazquez(1170)
The AI Product Manager's Handbook: Develop a product that takes advantage of machine learning to solve AI problems by Irene Bratsis(1024)
