Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Specify Superclass when Creating New Class

I have not been able to figure out how to specify a superclass when creating a new class in Android Studio. I know I can manually accomplish this using the extends keyword but I was wondering if there was a way to specify superclass while creating the subclass.

like image 405
ChemDev Avatar asked Mar 17 '23 22:03

ChemDev


1 Answers

The closest method I have found to achieve something similar is File and Code Templates. Press Ctrl+Alt+S and go to File and Code Templates in the IDE Settings. Now you can create your own template by clicking on the green plus sign.

Here's an example of one that I created based on the Class Template:

#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
#parse("File Header.java")
public class ${NAME} extends ${SUPERCLASS} {
}

The only difference between this and the default Class template is that I've added extends ${SUPERCLASS}. ${SUPERCLASS} is a custom variable which will be prompted to be used when using this template.

like image 110
Joel Avatar answered Apr 06 '23 18:04

Joel