Home > Article > Web Front-end > jQuery in Android: Introduction to AQuery_jquery
To show you what Android Query can do for user interface development, we’ve quoted an example from their project page.
This is the code before using AQuery:
This is the code after using AQuery:
The familiar jQuery syntax appears again, and I am very excited.
AQuery project address: https://github.com/androidquery/androidquery
Android Query simplifies the process of attaching event handlers. It doesn't build out interfaces or anonymous classes, we just need to make sure they don't misspell the event handler method name.
Trivial issues caused by screen size and API version can cause a lot of trouble for the device. Android Query solves part of the problem by providing its own wrapper around the API. For example, the function "aq.hardwareAccelerated11();" will detect whether the device supports API 11 and start hardware acceleration when appropriate.
When dealing with different screen sizes, developers often create the tablet first, then remove and identify controls until it fits the phone. Generally this means that before trying to manipulate controls from code behind, you need to check the virtual tree to see if they have indeed been created from the axml file.
Android Query will conditionally chaining methods, allowing you to avoid all checks. Consider this code:
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 also makes it easy to invoke asynchronous HTTP requests. It includes support for simple and multi-part POST operations, and can accept data in binary, JSON, HTML, and XML formats. Additionally, it includes separate support for images, allowing us to download the image, cache it, and load it into the control with a single line of code.