Kevin Coulombe
Kevin Coulombe

Reputation: 1575

Android Studio "Import class" action adds fully qualified name

Using Android Studio, when I type the name of a class which I have no import for and use the "Import class" action (using either ALT-ENTER or choosing the "Import class" action from the CTRL-A menu), it simply adds the package name in front of my class.

For example,

Intent i = new Intent(Intent.ACTION_SEND);

becomes

android.content.Intent i = new Intent(Intent.ACTION_SEND);

Is there any way to have the "Import class" action add an import to the file by default instead of adding the fully qualified name like this?

I am quite certain it used to work as I describe. Unfortunately, I cannot tell what changed since then and I would like to avoid reinstalling the IDE and reconfiguring everything to my liking.

My configuration

In the Intentions settings, the option "Imports / Replace Qualified Name with Import" is checked.

In the Editor settings, the "Add unambiguous imports on the fly" option is unchecked and "Optimize imports on the fly" is checked

Upvotes: 16

Views: 4779

Answers (1)

Paulied67
Paulied67

Reputation: 323

So I did the same thing. It took me a while to realize, but I had checked the (menu) File --> Settings (in dialog) Code Style --> Java --> Imports (tab) --> "Use fully qualified class names" checkbox.

As soon as I un-checked that, Android studio stopped fully qualifying the class names that did not (yet) have import statements for. An example was when I was trying to cast to TextView in my code and it auto fully qualified it. Now it just adds it as an import at the top!

Note I am using Android Studio 0.5.9 in case my path to the checkbox is different than yours. Good Luck! Paul

Upvotes: 21

Related Questions