One of the least commented on, but far-reaching changes in Android, is a new signature for the ubiquitous findViewByIdI() method. It’s used by all Android developers, and has remained unchanged since the introduction of Android. If you wanted to save a view reference with specific type, such as Button or TextView, you’d have to include casting syntax. But with the new generic declaration of the method’s return type, the casting expression is no longer needed.
- [Instructor] One of the least commented-on…but far-reaching changes in Android was a new signature…for the ubiquitous findViewById method.…This method is used by just about all Android developers…to get references to view objects in layouts.…Traditionally, when you call findViewById,…it returns a view object.…If you want to cast it as a specific type,…you have to including Java-casting syntax.…But in Android 8, API level 26, a change was made…to the signature of the findViewById method.…
This method now uses generic typing.…Instead of returning a standard view object,…it returns a type that extends view, and that means…that you can return any specific concrete type…without having to explicitly cast the result.…In this application, which I've upgraded to use…Android 8.1, API 27, I see the results in Android Studio.…My casting syntaxt is now shown in dim characters,…and if I move the cursor over,…it tells me that the casting is redundant.…
Now, I can fix these one at a time.…I'll simply click into the type and press alt enter,…
Author
Updated
4/20/2018Released
7/14/2017Skill Level Intermediate
Duration
Views
Q: Why can't I earn a Certificate of Completion for this course?
A: We publish a new tutorial or tutorials for this course on a regular basis. We are unable to offer a Certificate of Completion because it is an ever-evolving course that is not designed to be completed. Check back often for new movies.
Related Courses
-
Android App Development: Communicating with the User
with Joe Marini1h 12m Intermediate -
Building Android Apps with Cloud Services
with Albert Lo2h 37m Intermediate -
Android App Development: Data Persistence Libraries
with Annyce Davis3h 59m Intermediate
-
New This Week:
-
Introduction
-
Welcome43s
-
-
1. Android Development Tips Weekly
-
Play sounds with SoundPool8m 45s
- 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.
CancelTake 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.
Share this video
Embed this video
Video: Clean up calls to findViewById()