The popularity of jQuery has become a fact. It greatly reduces the amount of code required to execute asynchronous tasks and operate the DOM. The new project AQuery wants to provide the same functions for Android Developers. In order to show you what Android Query can do for user interface development, we reference an example on their project page.
This is the code before using AQuery:
This is the code after AQuery is used:
The familiar jQuery syntax has emerged again, and there is a lot of excitement.
AQuery Project address: https://github.com/androidquery/androidquery
Android Query simplifies the process of appending event handlers. It does not build interfaces or anonymous classes. We only need to ensure that they do not spell the method names of the event handler.
The Code is as follows:
Aq. id (R. id. button). clicked (this, "buttonClicked ");
The trivial issues caused by screen size and API version may cause a lot of trouble for devices. Android Query solves some problems by providing its own encapsulation around APIs. For example, the "aq. hardwareAccelerated11 ();" function checks whether the device supports API 11 and starts hardware acceleration when appropriate.
When processing screens of different sizes, developers often first create a tablet and then delete and recognize the control until it can match the phone number. This generally means that before trying to operate controls from the background code, you need to check the virtual tree to see if they have been created from the axml file.
Android Query links the methods (conditionally chaining methods) based on the conditions, so that you can avoid all checks. Consider this Code:
The Code is as follows:
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, all subsequent setting methods and Event Handlers will stop. Although this may make debugging more difficult, it can greatly reduce the number of lines of code in the onCreate method.
AQuery can also easily call asynchronous HTTP requests. It supports Simple and multiple POST operations and can accept data in binary, JSON, HTML, and XML formats. In addition, it also contains a separate support for images. We can use a line of code to download the image, cache it, and load it into the control.