[Android] Eclipse shortcuts i use most

It is worth to spend some time reading about the shortcuts eclipse offers you to save switches / context-changes and become much more productive when coding. One of the most useful tutorials is this one from vogella. After a few years coding, the ones i consider most useful are these: (yellow ones are the best time savers for me)

ctrl+3: quick access to resources
ctrl+2: quick assist – rename/assign tools (renaming vars, assigning operations to local vars)
ctrl+1: quick fix (see my strings resources tutorial)
ctrl+I: automatic code indentation
ctrl+shift+O: fix imports
alt+left: go to previous location
alt+right: go to next location
ctrl+right: move to next text element
ctrl+left: move to previous text element
ctrl+alt+down: clone selected line below (next line)
ctrl+alt+up: clone current line above (previous line)
alt+up: move current line up
alt+down: move current line down
ctrl+D: delete current line
ctrl+DEL: delete next element
ctrl+backspace: delete previous element
shift+enter: adds a new line below current, without deleting or overwriting selection
ctrl+Q: back to the last edited position

And of course, the most traditional and obvious ones:

ctrl+F: find
ctrl+X: cut
ctrl+C: copy
ctrl+V: paste
ctrl+Z: undo
ctrl+Y: redo

I suggest you to correct some bad customs and get used to these shortcuts, and you can focus more on coding and less in interruptions/switches/context changes that often act as obstacles.

Have a nice coding day! 🙂

Advertisements

Another time-saver! Creating String resources directly from Code editor

Write a string literal in your code like

mButton.setText("Text to add as String resource");

Then select the string literal  like this:

 1-select-text

and press ALT+SHIFT+A, a yellow menu will appear in the bottom-right corner,

2-bottom-menu

double click on “Extract Android String” , this menu will appear:

2.-add-str-res

choose a proper name for the String resource and click Ok.

You will get a new strings.xml entry:

   <string name="my_string_resource">Text to add as string resource</string>

And your Button’s setText line replaced by:

   mButton.setText(R.string.my_string_resource);