In Android studio, If you want to create a new Class extends a SuperClass, built-in menu doesn’t provide option for it.
Create a Class extends a SuperClass
Where as you can only Create a new Class and then manually write down extends Superclass.
To add Create new Class which extends a SuperClass, you need to Create a new Template
Press Ctrl+Alt+S to open Settings window, here search for File and Code Templates
Click + button to add new template, give a name as Inheritance(you can give any name) and write this below code
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != “”)package ${PACKAGE_NAME};#end
#parse(“File Header.java”)
public class ${NAME} extends ${SUPERCLASS} {
}
Apply it and the Click Ok button. as shown below
Now go to project and try to create new class as shown Image 1 above..
and you’ll see newly added template in dropdown as shown below.
Select it and then you’ll be asked to enter Super class name. Enter your Super class name.
That’s it.
You’ll see new Class created with SuperClass.
Hope it helps somebody.
You may also interested in
- No Update and Restart button to download latest version in Android Studio,
- Integrate BitBucket Plug in Android Studio,
- Issues after updating to Android Studio 2.0v
- Unmappable character for encoding UTF-8 in Android Studio
- Useful Keymap Shortcuts and Settings Android Studio Startup guide
- Android Studio ADB wipes out logcat quickly when app crashes
2 thoughts on “Create new Class extends a SuperClass- Android Studio”
I tried the same thing but it is displaying some error message: “Unable to parse template Superclass” Error message: Lexical error: org.apache.velocity.runtime.parser.TokenMgrError: Lexical error at line 1, column 44. Encountered: “\u201c” (8220), after : “”
Can you please tell what is wrong with my code.
same here