How to fix "Organize Imports" in Android Studio for static imports

android, android-studio, java

Solution

The answers of this post will help you.

- set the packages you want import in `Settings -> Code Style -> Java -> Imports`

- press `ctrl+space two times` and then `alt + enter` to import it statically without full qualifier.

Problem

I'm using version 0.3.7 of Android Studio, and I'm trying out OpenGL ES programming. This requires a lot of imports from such classes as "android.opengl.GLES20" Instead of auto importing GLES20 and accessing for example, the GL_COMPILE_STATUS variable like so: ``` glGetShaderiv(shaderObjectID, GLES20.GL_COMPILE_STATUS, compileStatus, 0); ``` I'd rather type in GL_COMPILE_STATUS and have it auto import the following: ``` import static android.opengl.GLES20.GL_COMPILE_STATUS; ... glGetShaderiv(shaderObjectID, GL_COMPILE_STATUS, compileStatus, 0); ``` And have the above import found as I type in GL_COMPILE_STATUS. But the current system will not know that GL_COMPILE_STATUS comes from the GLES20 class. So my question is this, is there a way to assist the organize imports functionality in Android Studio for finding these variable? I'd like to keep my code to a minimum, and having to write GLES20. in front of everything is a little off putting - and I won't use a wildcard import as I consider that bad practice.

Original source

Related problems