Home  >  Article  >  Web Front-end  >  jQuery in Android: Introduction to AQuery_jquery

jQuery in Android: Introduction to AQuery_jquery

WBOY
WBOYOriginal
2016-05-16 16:49:311457browse

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:
jQuery in Android: Introduction to AQuery_jquery

This is the code after using AQuery:

jQuery in Android: Introduction to AQuery_jquery

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.

Copy code The code is as follows:
aq.id(R.id.button).clicked(this, "buttonClicked");

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:

Copy 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 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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn