December 20, 2014
Hot Topics:

Eclipse Refactoring for Android, Page 2

  • November 1, 2012
  • By Jessica Thornsby
  • Send Email »
  • More Articles »

4) Remove Container

As the name suggests, 'Remove Container' removes a container and places its children in the parent of the removed container. When you select 'Remove Container' from the 'Refactor' menu, Eclipse opens a preview dialog where you can assess the code changes before applying them to your project.

Refactoring Android in Eclipse

5) Extract Style

If you want to create reusable layouts, styles and themes, the 'Extract Style' option allows you to extract layout fragments and define them as style rules. Once you've clicked 'Extract Style' the wizard will display a list of attributes and their associated values.


Refactoring Android in Eclipse
Click here for larger image

In this dialog, you can choose to remove the extracted attributes, or remove all the attributes of the same name, to create a more unified layout. If an attribute value occurs more than once, Eclipse places a number beside that attribute, allowing you to see at a glance which attributes are the most common.

6) Extract as Include

'Extract as Include' is a visual refactoring operation that supports the reuse of layouts, and is useful for sharing visual elements between layouts. Essentially, this operation allows you to take a section of XML and extract it into a new layout file. Eclipse can also add an {include} tag in the view's original location, linking to the new location.

To extract an element into a new layout:

  • Select the item and choose 'Extract as Include' from the menu.
  • Enter a name for your new layout file

    Refactoring Android in Eclipse

  • Select 'Ok' to pull views from your original layout and automatically create a new layout file.

Tip. In most instances, it is good practice to ensure that the 'replace occurrences in all layouts with include to new layout' checkbox is ticked.

7) Extract Android String

If you're using hardcoded strings in your project, it can be useful to store them in a dedicated strings.xml file, which also allows you to see all the string resources at a glance. In Eclipse, extracting a string is simply a matter of:

1) Select the string you wish to extract.

2) Open the 'Refactor' menu, followed by 'Android' and 'Extract Android String.'


Content Assist for Android
Click here for larger image

3) Enter a new name for your string, optionally edit the string text and define where you wish to place the string. Unless you specify differently, the string will be placed in the res/values/strings.xml file.

4) If you need to, you can specify whether the string should be replaced in all Java files, or in all XML files, using the checkboxes.

5) After you've entered all the relevant information, click 'Ok' to extract the string.

Eclipse Refactoring for Android

Eclipse is an established and powerful IDE that offers integrated functionality to make developing your app faster, easier and less error-prone. In this article, I demonstrated how Eclipse's refactoring options can automate potentially complicated operations. Simplifying these operations using refactoring can help you create and ultimately ship your Android applications faster and with less hassle.

To find out more about how Eclipse can give your day-to-day productivity a boost, check out the Juno documentation, which is a great source of up-to-date information on this powerful IDE.


Tags: Eclipse, Android App development

Originally published on http://www.developer.com.

Page 2 of 2



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Rocket Fuel