JQuery in Android: AQuery introduction _ jquery

Source: Internet
Author: User
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.

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.