I would like to improve my productivity by creating some shortcuts
For example, when I type :
toast(var)
and hit Enter, it substitutes with :
Toast.makeText(this, var, Toast.LENGTH_LONG).show();
And a few others of the same kind. Is there a way to do this in IntelliJ/Android Studio?
Thanks
You need to use Live Templates.
If you go to Settings > Live Templates then you will be provided with a list of groups and templates within them. If you right click on the pane and select Move > New group... then you can create a group to store your own custom templates.
Once you have created a group, select it and click the little green plus sign in the top right and choose Live Template. This will create a new template in your custom group.
In the Abbreviation box put toast and you can leave the description blank. Then in the Template text box put Toast.makeText(this, $var$, Toast.LENGTH_LONG).show();. The final step is to click the Define link below and select Java.
Now to test it out. What this will do is when you type the abbreviation text, in our case toast, in a .java file and press tab(by default) then it will write out what we added to the Template text box. Then it will place the cursor at the $var$ position in the text.
You can follow this routine for other kinds of templates that you may wish to do. I would recommend having one for logging to logcat.
Related
usually when we highliting a word on phone, it will have a pop up list that contain function like copy, paste, search such functions. Is it able to change the pop up list so that i can modify it to other function?
Check about ActionMode APIs. You can remove all functions and add custom function.
Wherever your carret on a name that you want to change is
if you call for autocomplete (ctrl + space)
you will get a new full name instead of the only the part after carret(which is needed in this example)
The only possible way to choose another name in a clean way is to place carret at the end of the previous name
but when you want to change a name from the middle of the previous name
you have no choice other than accept the suggested name
and then delete the residue text from the previous name
Comparing previous text with new selected text from autocomplete suggestion box is implemented on many code editors. Is there any specific reason that Android Studio team decided to not to implement this feature? or may be this feature exist but is turned off by default for some reason and if this is the case how could we turn it on?
Just use TAB instead of ENTER to autocomplete changing the old value. It also works for methods.
I am using edit text field in the map. When i click on the map i will get the location name in the edit text field. Now i want to use the same edit text field for searching any location i want to go.
I saw one tutorial here for searching location by name in google map. But i want to use same edit text field for two different actions.
here is an example.
case R.id.menu_enableTraffic:
myMap.setTrafficEnabled(true);
return true;
if i click on the enable traffic option means it enables traffic in map.
Like wise when i click on the search menu option then i want to use same edit text field for searching location.
sorry for my bad english.
Yes, it is possible since you are using different buttons for doing two different things. Attach listener to each of the two buttons and get text from the same edittext and use it for search in search click and use it to show traffic when enable traffic option is clicked.
I hate when I try to open the declaration of a layout and Eclipse redirects me to the R file, which is the same as nothing. Is there a keyboard shortcut for it to take me to the layout file. I know if you click on it with CTRL it gives you this option on a pop-up, but I hate using the mouse. I can't find this on the keybinding section. There's just plain "open declaration" which I have already changed because it was a horrible F3 by default, but this usually takes you to the R file
Well there is a mouse shortcut - Just hold down CTRL and hover over the id you want to see. You'll get two options, one for R.java and other to open the declaration. Choose the second one
EDIT:
Sorry, completely missed the part where you dont like the mouse use. Well I dont think there is any other way, and I see a bug/feature request here https://code.google.com/p/android/issues/detail?id=53536 reported specifically asking for this, so I wouldnt think another way exists other than either using the mouse or using the keyboard to highlight the particular item of interest and using Ctrl+Shift+R to get the menu and pressing Enter but like you mention this wouldnt work for something like R.id.foo . Wish someone from Google/Eclipse could comment on the bug/feature request.
If you CTRL + Shift + r : you can open any resource.
Using this with any text selected will pre-populate the open resource dialog with the text you selected. After that you should be able to find the file you want very quickly and double click it to open (or use down arrow and enter for openting without using a mouse).
Hope this helps.
Pretty new to android so excuse me if this is a really obvious question.
Say my application has a bunch of TextViews, each one showing the attributes of a certain product (name, price, etc). I have a button next to each of these TextViews labeled "modify".
How do I make it so that when I press the modify button next to a certain attribute, a popup window with a space to enter text into comes up so that the user can enter text into this box and then have the actual attribute listing on the original page change? Actually I just need a push in the right direction with creating this popup text field... not sure if there is already some built in functionality for this or if not, what would be the best way to create this kind of thing.
Thanks.
Why not have the modify button set TextEdit.setEnabled(true); and then change focus with TextEdit.setFocus? Note that both of these are inherited from view
If you really want a dialog you might want to looking into the AlertDialog.Builder. I know you can use it with buttons and radio buttons, but I'm not sure you can get it to work with a TextView.
Use a code like this for the input popup: Android dialog input text
In the positive button handler, set your edittext content programmatically like this:
myEditText.setText(value).
As simple as that. The only difference with a standard GUI framework is that you don't retrieve the value as a result of the popup function. Instead, you must provide an action handler.