Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 210
Jakub Turcovsky Avatar asked Jun 09 '17 09:06

Jakub Turcovsky


People also ask

How do I import a live template?

Choose File | Manage IDE Settings | Import Settings from the menu. Specify the path to the archive with the exported live template configuration. In the Import Settings dialog, select the Live templates checkbox and click OK.

How to import template in Android Studio?

Go to File -> Export Settings , choose only Live templates , and export it to a file. Then you can use File -> Import Settings and provide this file to import live templates.

What are live templates?

Use live templates to insert common constructs into your code, such as loops, conditions, various declarations, or print statements. To expand a code snippet, type the corresponding template abbreviation and press Tab . Keep pressing Tab to jump from one variable in the template to the next one.


1 Answers

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.

like image 143
dj_frunza Avatar answered Oct 02 '22 20:10

dj_frunza