Refactoring code makes you more efficient -- you can rename files, variables, methods and more. You can extract code and use it in new ways. Android Studio has strong refactoring functions, which you'll learn about in this tutorial. This online video shows you how to rename variables and make other changes that will help you understand how to refactored code in order to save time and complete your projects more quickly.
…Android Studio has powerful code refactoring…capabilities, letting you rename methods, variables…and fields, rename files, extract code to new methods and so on.…I'll show you how to get to these features…and then demonstrate a few of the most common ones.…I'll start with renaming a simple variable.…On this line, I've declared a variable named tv that refers to a TextView widget.…In order to really see the effect of refactoring,…I need at least one reference to this variable.…
So I'll add a new line of code, and I'll make a…tv.setText, and I'll set the text to a literal value of New text.…Notice the light bulb that appears over on the left.…I've shown that previously, and this is going to…let me extract this string to a string resource.…I'll press Alt + Enter, choose Extract String…Resource and I'll set the resource name to new_text.…And when I click OK, that new resource is added to my strings.xml file and…now the code reflects a reference to the resource instead of the literal string.…
I can jump to that file by Ctrl-clicking.…
Note: This course was revised on 8/20/2014 to reflect changes in the .0.8.4 beta version of Android Studio.
- Exploring Android Studio and IntelliJ IDEA
- Installing Android Studio
- Creating projects with Android Studio
- Navigating the user interface
- Designing activity layouts
- Analyzing and refactoring code
- Debugging and packaging apps
Skill Level Beginner
Q: This course was updated on 8/20/2014. What changed?
A: We revised this course to reflect changes to the Android Studio beta, released at the 2014 Google I/O conference. This update was recorded with Android Studio .0.8.4, which contains a new project wizard and updates to the Gradle build system. For more information about the changes in this course, check out the "What's new in this update" movie.