JQuery in Android: introduction to AQuery

  • 2020-03-30 02:50:56
  • OfStack

To show you what Android Query can do for user interface development, we cite an example from their project page.

This is the code before using AQuery:
< img SRC = "border = 0 / / files.jb51.net/file_images/article/201405/201456100525244.png? 20144610550 ">

This is the code after using AQuery:

< img SRC = "border = 0 / / files.jb51.net/file_images/article/201405/201456100602598.png? 20144610616 ">

The familiar jQuery syntax is back.

AQuery project address: (link: https://github.com/androidquery/androidquery)

Android Query simplifies the process of attaching event handlers. It doesn't build interfaces or anonymous classes, just make sure they don't misspell the method names of the event handlers.

aq.id(R.id.button).clicked(this, "buttonClicked");

When working with screens of different sizes, developers often create a tablet first, then remove and identify the control until it matches the phone's case. This generally means that before attempting to manipulate controls from background code, you need to check the virtual trees to see if they have actually been created from an axml file.

Android will Query link method according to the conditions (conditionally chaining the methods), so you can avoid all inspection. Consider this code:

aq.id(R.id.address).text(name).background(R.color.red).textColor(R.color.black).enabled(true).visible().clicked(this, "addressClicked");

If the control address does not exist, then all subsequent setup methods and event handlers stop. Although this can make debugging more difficult, it can significantly reduce the number of lines of code in the onCreate method.


Related articles: