Search code examples
androidandroid-studiogroovyandroid-studio-2.3live-templates

How to import project's R in Live Template automatically?


I'm trying to create a live template for Fragment's onCreateView(). This is my template now:

Live Template

After using it, R wants to be manually imported.

Result

How can I import application's R by default? Or can I somehow get the project package name with a groovy script and write it before R like $PACKAGE_NAME$.R.layout.$LAYOUT_NAME$ to make it work?


Solution

  • Enabling the "Add unambiguous imports on the fly" in File -> Settings -> Editor -> General -> Auto Import -> Java might solve your issue since it will automatically import the R class on the fly, and the need to manually import it will disappear.