In this video, Doug Winnie walks through how to connect Java code to Activity widgets from XML. In your XML, you need to define an ID for each object you want to access in the code. Then in Java, you create instances of the widget classes, and assign them views using the findViewById method, casting as needed based on the widget type.
- [Instructor] To make your project interactive,…you will build code, in Java.…Java will be used to tell your app what to do,…when the user interacts with widgets,…or other components, in your game.…In our case, we have a button widget,…that we need to hook up to do something,…when the user clicks it.…To connect the widget to Java, we need to use the IDs,…and create objects, in the Java code,…to link to the widget IDs, in the activity.…Let's start with a content_main.xml file…located in the project panel,…under res, layout, content_main.xml.…
If we look at the xml code, in text view,…we will see our two widgets, our text view,…and button widgets, we worked with earlier.…Our text view displays text, but,…we don't have an ID name associated with it.…In order for our program to access the widget,…in code, we need to give it an ID.…We're going to wire our app, so that when we click…the button, it displays a message, in the text view widget.…So, the first thing we need to do,…is to give our widget a name.…Along the way, we'll also resolve the error…
- Installing Android Studio
- Coding in Java and XML
- Getting a head start with starter templates
- Working with emulators
- Creating a project, variable, and toast
- Connecting XML widgets to code
- Adding images
- Adding game logic with conditional statements and operators
- Changing the data or design
Skill Level Beginner
1. Android Basics
Test your setup2m 56s
3. The Major Parts
4. Make an App
5. Tinkering with Your App
Next steps1m 4s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.