From the course: Android Development Tips

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Clean up calls to findViewById()

Clean up calls to findViewById() - Android Tutorial

From the course: Android Development Tips

Clean up calls to findViewById()

- [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…

Contents