MobileJava MobileMastering Eclipse Content Assist for Android

Mastering Eclipse Content Assist for Android

Developer.com content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

When you’re just beginning to develop Android apps in Eclipse, your immediate concern will be coming to grips with the ins-and-outs of a new platform, but once you’ve mastered the essentials you’ll want to focus on making development easier, less error-prone and ultimately faster. This is where some extra Eclipse know-how comes in handy.

As essential way to speed up your day-to-day development work is to harness Eclipse’s powerful and time-saving ‘content assist’ feature. Content assist provides context-sensitive code completion via a pop up window, saving you from typing out every line of code in full, while also reducing the chances of spelling mistakes and typos.

Accessing Eclipse Content Assist for Android

To access content assist for Android, press Ctrl and the space bar. This will open a pop up containing potential endings for whatever code you’re currently typing.

Content Assist for Android

If you’re not a fan of keyboard shortcuts, the content assist option can also be found in Eclipse’s Edit menu.

In this example, I’ll use the simple scenario of specifying the width parameter for TextView to demonstrate how you might use content assist for Android in your project.

  1. Type android:layout and press Ctrl+space. This will activate content assist with its list of context-sensitive proposals.
  2. Scroll down until you find the desired attribute. In this example, we are looking for ‘width.’
  3. Clicking on widthonce opens a short description of the option (note, a description is currently not available for all options.)

    Content Assist for Android

  4. Double clicking, or pressing Enter inserts this attribute into your code.
  5. Press Ctrl+space again and content assist will suggest new context-sensitive attributes.

Tip:You can press Ctrl+space without typing anything first if you wish to view all the constants and methods of a class.

Troubleshooting with Content Assist for Android

Despite being such a useful and intuitive tool, Eclipse’s content assist for Android functionality can sometimes be a source of pain for Android developers, as it may stop working when you update your Eclipse installation — or seemingly stop working at random! In this section, we’ll address some common complaints and share some techniques for getting content assist for Android back on track.

Content Assist Is Displaying ‘No Default Proposals’

If your code completion window is displaying a ‘No Default Proposals’ message, your default options might be at fault. To address this:

  1. Open the Windows menu.
  2. Select Preferences.
  3. Double-click the Java button on the left-hand menu.
  4. Double-click Editor, followed by Content Assistant.
  5. Select Advanced.
  6. Select the proposal kinds contained in the default content assist list. This should solve your No Default Proposals problem.

Content Assist Is Always Displaying the Same Non-Usable Suggestions

If content assist is constantly bringing up non-usable suggestions (for example “default namespace – Default namespace attribute” or “xsinsp – XML schema namespace”), the problem may be that your XML file has been assigned to the XML editor, rather than the customized Android XML editor. To check whether this has occurred in your installation:

  1. In Eclipse’s Package Explorer, right-click on the XML file where you’re struggling to call content assist.
  2. Select Open Withfrom the subsequent menu.

    Content Assist for Android

  3. Ensure the Android Common XML option is selected. If it isn’t, then chances are this is behind your content assist for Android problems.

Upgrading to Eclipse ‘Juno’ Has Broken My Content Assist

If you’ve just upgraded to the latest, ‘Juno’ release of Eclipse, you may suddenly start seeing the dreaded “No Default Proposals” when you call content assist, despite it working perfectly before. In this situation, there are several possible fixes that can get content assist running smoothly again.

Restore Defaults

  1. Open the Window menu, followed by Preferences.
  2. Select Java from the left-hand menu.
  3. Select Editor, followed by Content Assist.
  4. Select Advanced.
  5. Click the Restore Defaults option.

Content Assist for Android

Java Proposals

If this doesn’t solve the problem, re-open the above dialog and ensure the Java Proposals checkbox is selected in the Default Proposal Kinds box.

Content Assist for Android

And If All Else Fails …

Closing and restarting Eclipse in ‘clean’ mode will remove cached data stored by the Eclipse runtime and force cache reinitialization. This should rectify any outstanding issues with content assist for Android.

  1. Close your Eclipse installation.
  2. Locate the eclipse.inifile.

    Content Assist for Android

  3. Select the Edit option, and open the file in Notepad.
  4. Add -cleanas the first argument on the first line.

    Content Assist for Android

  5. Hit Save.
  6. Restart Eclipse. Note, Eclipse will typically take much longer to load with the -cleanargument in place, so be patient!

    Tip: After you’ve run the -clean argument once, you should remove it. Leaving the -clean argument in the eclipse.ini file means you will keep encountering these increased startup times.

Alternatively, you can open a clean installation using your Eclipse shortcut.

  1. Right-click on your shortcut.
  2. Open the Properties dialog.
  3. Select the Target box, and type the -cleanargument after the current Target.

    Content Assist for Android

    Again, remember to remove the -clean argument once you’ve finished with it, as it greatly increases Eclipse’s load time.

Conclusion

Having content assist for Android handy can greatly increase your productivity. Not only will it save you typing out every character of your code, but its context-sensitive nature means you are less likely to insert the incorrect code or make typos/spelling mistakes, which aren’t always easy to spot. In this article, we covered the essentials of coming to grips with content assist for Android, and shared some tips for keeping this useful functionality running smoothly.

Eclipse has plenty more ways to accelerate your day to day development work – if you’re interested in learning more, then the Juno documentation is a great source of up to date information.

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Latest Posts

Related Stories