I'm creating a new project in Android Studio. I'm used to development in Eclipse, and I can simply hover on symbols that are not resolved and I'm able to import the dependencies. Now when I hover on the symbols, I'm simply informed "Cannot resolve symbol X" with no option to import the dependency, even for simple ones like TextView. How do I auto resolve/import these symbols?
Thanks.
One way is to place the cursor anywhere inside a class name (either by clicking with the mouse or moving the cursor with the arrow keys) then press Alt-Enter or right click. Usually the first option will be to import the class. You can also press Ctrl-Alt-O to optimize imports. I know this will remove unused imports and I think it will add missing imports.
Related
I've started today with Android Jetpack Compose. At the beginning it worked all fine. On some classes you just have to watch that you get the right package. But on some Point I've messed something up an I don't know what. I've just wanted to Import a package and then some context menu popped up, I accidentally pressed 'Ok' and since then the "Import" doesn't show up anymore when I write a class from a compose package.
There is surely an option I've turned off but I don't know what. Can anyone help me with this?
Go to file > Settings in Android Studio then search in the settings for "imports".
Under editor click Auto Import and scroll down to the bottom.
The check the two boxes for Kotlin as shown here:
.
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.
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 :-)
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.
I have been messing around with Android Studio and so far I like most of what I have seen. One thing that has been annoying me though is this lack of "Table of Contents" for a class. I apologize for not knowing exactly what to call it. But what I am referring to is the dropdown menu in eclipse that lists all the methods, interfaces, classes and so on that are in that class file. This then allows you to jump to that position. This view is when you are in "Package Explorer" and click the arrow to the left of the class. This is one thing that makes me really miss eclipse. I know that you can easily search with Ctrl+F inside a document but I often forget the method names. I tried looking through here but to no avail. Just wondering if anyone knows some way to handle this.
IDEA has a tab called "Structure", which shows all the methods, fields, etc. of the currently-open class.
I've just got a Tip of the Day popup in Android Studio helping with exactly this problem.
You can quickly navigate in the currently edited file with
Ctrl/⌘+F12 (Navigate | File Structure).
It shows the list of members of the current class. Select an element you want to navigate to and press the Enter key or the F4 key. To easily locate an item in the
list, just start typing its name.
Also, as danny117 points out, you can use Alt/⌘+7 to show / hide the same content in a side panel view (shown above in Chris Jester-Young's answer).
View > Tool Windows > Structure
In addition to what Chris Jester-Young said, it's worth pointing out how to see the methods and properties of a class pointed by the cursor.
a) Type Ctrl + H in the class pointed by cursor.
b) In the class name, in the hierarchy window, double-click the class name. The system, upon confirmation, will decompile and open the class code.
c) Alt + 7 (Windows) or Command + 7 (MAC) to display the structure window.
d) One can now visualize properties, methods, derived classes, derived interfaces, and even include inherited items. All related to the class under the caret.
I'm currently using Beta 0.8.9 of the Android Studio and what you need to do is click on the settings icon in the Android Project View. If you select 'Show Members' then the Classes become expandable and you can navigate around the class using the project view.