Question

I am currently learning to develop apps for Android-based devices, and I have a pretty decent hold on Java, so learning hasn't been too challenging for me. However, I am lazy, and I don't want to import each individual Android class that I need. In one of my .java files, if I was to type:

import android.*;

It would compile fine. However, if I was to type:

public class example extends Activity{...}

Below the former piece of code, Eclipse/ADT still tells me I need to import the android.app.Activity class. So, is there another way I could import all the android classes in order for me to save the time of importing each one individually?

If not, I'll be a good sport and get over it, but it would be really convenient, nonetheless.

Was it helpful?

Solution

So, is there another way I could import all the android classes in order for me to save the time of importing each one individually?

import android.*; will only import classes and interfaces that are directly in the android package. To import all classes/interfaces in android.app, use import android.app.*;.

Bear in mind that Eclipse/ADT provides multiple ways of adding the imports for you, such as Ctrl-Shift-O to resolve all missing imports.

OTHER TIPS

You can also use Eclipse/Adt setting "Organize Imports" in Java ->Editor -> Save Actions to allow Eclipse organize your imports on save. Very useful. Also you can customize the setting in Java -> Code Style -> Organize Imports.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top