You deserve to have the Android studio development Tips _android

Source: Internet
Author: User
Tags static class

The last time I sent an introduction to studio, here is another supplementary.

As we all know, the capabilities of the Android studio are very powerful and intelligent. If someone tells you to learn to use the command line for Android development, you can tell him that Android studio is Google's offer to developers to improve efficiency. Imagine you have a bunch of ideas in your head, but it's too low to develop the coding so that ideas are lost or interest disappears. Okay, no more nonsense, here are a few more useful tips and shortcuts to improve our coding efficiency.

1. Complete a sentence code

If we call a method and pass the argument to the method, this time if we want to end the statement, we move the cursor to the end of the line with the mouse or the arrow key, and then enter the end of the carriage. In fact, the efficiency is very low, why? Because our hands on the keyboard, to touch the mouse and the direction of the key distance are relatively far. So here's a combination of shortcut keys to complete the code:ctrl+shift+enter

As you can see here, after we call the method and use the shortcut key directly, studio jumps to the end and adds a semicolon, and if we click the shortcut again, we jump to the next line. If you think this shortcut is a bit long (I think so), you can simplify this feature by customizing the shortcut keys. Here are some specific steps:

① Open Settings

② Select Keymap

③ Click on the button to the right of the search box

④ Press you need to modify the corresponding shortcut key, that is, Ctrl+shift+enter, will search for the corresponding shortcut keys, double-click the corresponding shortcut key settings, click the button will appear in the following figure

⑤ Select the first option to add a shortcut key, the following image appears

Can be directly in this interface you want to press the shortcut key combination, you can see if there is already a shortcut, then there will be a yellow exclamation mark warning, we can try more, choose the most convenient to their own. I set the alt+m, M is the meaning of moving, so I remember.

2. Open the document

The last time you introduced the studio's settings, let the mouse hover over the code to open the document, but the default is not. Documentation is the most important object of our study, and the first thing to think about when encountering a problem is the document. The shortcut key for opening a document defaults to:ctrl+q, we need to know that this will not only allow us to open the document in the code, but also open the corresponding completion document when the code is complete, you can look at the following figure

Here in the completion of the time if we do not know the usefulness of the IsEmpty method, you can first move the cursor to the fill position, and then press the shortcut key, you can open the corresponding document.

3. Hint Method parameter

Sometimes we write and we forget the method to pass in a parameter of what type, this time, you can use the shortcut key:ctrl+p, the effect is as follows

When the cursor is in the method, press the shortcut key, Studio will prompt us the parameters that this method needs, this is also more commonly used.

4. Copy Code

Select your code and press the shortcut key:ctrl+d, it's better than pressing CTRL + C and CTRL + V.

5. Quickly open file

When we need to open a file in the project, you can use the shortcut key ctrl+shift+n Open the Search box, and then enter the file name return. Pressing the shortcut key will get the following search box:

6. Jump to code declaration

Shortcut key:ctrl+b, this is not much to say.

7. Overriding the parent class method

Shortcut keys:ctrl+o

As you can see, when we open the selection box, we can directly enter the name of the method that needs to be rewritten to find it, and the matching direct return is good.

8. Security renaming

The advantage is that you do not have to manually modify each place yourself. Just move the cursor to the place you want to rename, press the shortcut key:Shift+f6, this time will prompt you to enter a new name, and then the system will search, find all the same name variables or methods, and then prompt to the user, the interface will be the following:

This place will show all use this variable or method of place, if we need to rename directly, you can click on the lower left-hand corner do refactor button to confirm, if there is no need to rename the place, you can select the line, right-click, select Exclude to remove.

9. Find where to use the method or class

When the project is large and the activity is being refactored, or the other code is being maintained, many times we need to know where a method is invoked, at which point a shortcut key: Alt+f7 to find all the places where this method is used.

10. Open a list of recently used files

Shortcut key:ctrl+e, this also does not say much, the official Google Demo video will often see engineers use this shortcut key.

Then I'll introduce some techniques other than shortcut keys.

1. If you want to judge whether a string is empty, would you do it like this?

2. If you want to traverse a ArrayList in reverse order would you do it like this?

3. What would you write if you were to write a corresponding bean based on a JSON data? Here you can use a more convenient plug-ins to do, the name is Gsonformat, we use this plug-in can be generated through a section of JSON corresponding class, how to download this plugin can be your own Baidu.

For example, there is a section of JSON data:

{
 "errnum": "0", "
 errmsg": "Success",
 "querysign": "3845925467,2370020290",
 "Retdata": [
  {
   "Rect": {"left
    ": "0",
    "top": "0",
    "width": "",
    "height": "To"
   },
   "word": "8"
  }
 ]
}

Plugin interface:

Using Plug-ins, you can directly generate a corresponding class code as follows:

public class Mybean {/** * errnum:0 * errmsg:success * querysign:3845925467,2370020290 * Retdata: [{] Re
 CT ": {" Left ":" 0 "," Top ":" 0 "," width ":" A "," height ":" "}," word ":" 8 "}] * * Private String errnum;
 Private String errmsg;
 Private String querysign; /** * Rect: {"left": "0", "Top": "0", "width": "A", "Height": "" "} * word:8 * * Private list<retdatabean> RETDA

 Ta

 Public String Geterrnum () {return errnum;}

 public void Seterrnum (String errnum) {this.errnum = Errnum;}

 Public String geterrmsg () {return errmsg;}

 public void Seterrmsg (String errmsg) {this.errmsg = errmsg;}

 Public String getquerysign () {return querysign;}

 public void Setquerysign (String querysign) {this.querysign = querysign;}

 Public list<retdatabean> Getretdata () {return retdata;}

 public void Setretdata (list<retdatabean> retdata) {this.retdata = Retdata;}
  public static class Retdatabean {/** * left:0 * top:0 * width:33 * height:31 * * Private Rectbean rect;

  Private String word;

  Public Rectbean GetRect () {return rect;}

  public void SetRect (Rectbean rect) {this.rect = rect;}

  Public String Getword () {return word;}

  public void Setword (String word) {This.word = Word;}
   public static class Rectbean {private String left;
   Private String top;
   Private String width;

   Private String height;

   Public String GetLeft () {return left;}

   public void Setleft (String left) {this.left = left;}

   Public String GetTop () {return top;}

   public void Settop (String top) {this.top = top;}

   Public String getwidth () {return width;}

   public void SetWidth (String width) {this.width = width;}

   Public String getheight () {return height;}
  public void SetHeight (String height) {this.height = height;}
 }
 }
}

This saves a lot of time.

Well, let's talk about it first, and then add it to the idea.

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.