Android Studio doesn't show import suggestion - android-studio

After trying adding the GSON library with "compile 'com.google...' ",I get a situation that when I try to import modules the IDE suggest me nothing except static and *. So I have to type everything. How can I fix it? I created new projects and still get this problem.

We're in 21 century and using modern IDE Android Studio. Why do you want to import packages manually just like we import when writing code in simple Notepad or any other text editor?
Just type the name of class which you want to use in your code. And the IDE is smart enough to show the suggestions which relates to your typed keyword.
I get a situation that when i try to import modules the IDE suggest me nothing except static and *.
Yes, it's indeed. Here is my screenshot
How can I fix it?
Very simple. Just type class name whatever you want and select it from suggestions. Android Studio automatically imports it.
For example (as per your requirement) you want to import #SerializedName() annotation. Type #Ser and hit Ctrl + Space and see the magic.
Now the Android Studio showing me the suggestions which matches with keyword Ser and I'll select SerializedName (com.google.gson.annotations.SerializedName). That's it.
Hope it'll be helpful.

Related

Android Studio: import org.tensorflow.Operation does not seem to work

I am using the latest Android Studio to create an image recognition project. I am using a .pb file downloaded from Github.
I have added "implementation 'org.tensorflow:tensorflow-android:1.5.0'" in build.gradle file.
When I go to the java file, the following two import statements are "unused"
import org.tensorflow.Operation;
import org.tensorflow.contrib.android.TensorFlowInferenceInterface;
Could somebody help? I am new to TensorFlow. Thanks!
Please ignore this question. I misunderstood what "unused" means.
Usually you don't have to add your imports manually. Android Studio shows some variants for imports and adds it automatically.
If your imports are grey and you get "unused" that means you didn't use them in this class so you can simply delete them.
It happens sometimes when you decided to write all imports before you actually code anything using these classes.
If you leave this warning nothing bad will happen but you use more memory than you actually need.

Android Studio auto importing wrong Context class

Android studio has been auto importing io.realm.internal.Context instead of android.content.Context and its getting very annoying. I have to highlight and manually type the import statement because Android Studio continues to auto import the wrong class. Is there any way to tell the IDE to not auto import certain packages? I never use the Realm context class, and whenever I reference Context for the first time it always erroneously imports that class.
It is possible to tell the IDE to not auto import certain packages. Please refer following steps:
In Android Studio go to
Settings>Editor>General>Auto Import
In the dialog box that opens, type the name of the class or a whole package to be excluded, and click OK.
Use new (Alt+Insert) and delete (Alt+Delete) to manage the list of classes and packages that IntelliJ IDEA shouldn't place to the suggestion list.
Apply changes and close Settings/Preferences dialog.
This will surely help :-)

Android Studio Not Recognizing Imports in TextView

I want to watch android sources code, but Android Studio has so many errors in base Android code. How do I fix these?
Since no one has jumped in here to help with this...
The longer answer here is that the imports (in red) are failing because Android Studio can't find them. So all the calls made to those libraries are failing. So ALL your code after that is full of errors.
For instance, the android.annotation.ColorInt seems to be broken. A quick Google search provides THIS: https://developer.android.com/reference/android/support/annotation/ColorInt.html
Which tells me that the reason that dependency is broken is because whatever you have there is deprecated and should now use a new reference.
Continue with this sort of research and your problem is solved.

Android Studio Alt+Enter auto import settings

I have a class in my Android Studio project called Ranking. I want to use this class in a different package in the same project, so I have to import the class. Normally I would type in "Ranking" and when it turns red, put my pointer on it and press Alt+Enter. This would bring up this menu:
After hitting Enter it would ask which class to import:
At some point I accidentally hit some keys while doing this for the Ranking class. I saw a window open and immediately disappear. This presumably changed a setting somewhere.
Now, whenever I use Alt+Enter this class is imported immediately without asking which one to import:
android.service.notification.NotificationListenerService.Ranking
When I hover over the class name, it doesn't say "Multiple choices" anymore as it does for Date:
I cannot find the setting. Does anyone know where it is?
on above setting select ask instead of All....
I just found it!
The option is under File -> Settings and then Editor -> General -> Auto Import
Here you can define classes that should be ignored by the Alt+Enter auto-import.

quick recap by option clicking a method/class for libgdx framework

Just created a first libgdx project and imported it into android studio. I am used to hovering over a method or a class and by option/alt clicking it, a little box shows up that tells me what this method/ class is good for. Is there a libgdx support for that kind of thing in android studio? It is a huuuge timesaver if you are a newbie like me.
AS is based on IDEA, Ctrl+Q should work for Quick Documentation when cursor is inside method or class name. You can also Ctrl+LeftClick to go to source of the class or method.

Resources