BT

InfoQ Homepage News Introducing AQuery: jQuery for Android

Introducing AQuery: jQuery for Android

Bookmarks

The popularity of jQuery comes down to one simple fact; it significantly reduces the amount of code needed to perform asynchronous tasks and manipulate the DOM. The new project AQuery seeks to do the same thing for Android developers working. To show you what Android Query can do for UI development, we cite a sample from their project page.

Before

After

Android Query simplifies attaching event handlers. Rather than building out an interface or anonymous class, one simply needs to ensure they don’t misspell the event handler’s method name.

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

Fragmentation due to differences in screen size and API versions can make getting the most out of a device difficult. Android Query some of these issues by providing its own wrappers around the API. For example, the function “aq.hardwareAccelerated11();” will detect whether or not the device supports API 11 and enable hardware acceleration if appropriate.

When working with different screen sizes, one often starts with a tablet and then removes and reorganizes controls until it fits on a phone. Normally this means you have to inspect the visual tree to see which controls were actually created from the axml file before you attempt to manipulate them in the code behind.

Android Query lets you side-step all the checks by conditionally chaining methods. Consider this snippet:

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 doesn’t exist, all of the setters and event handlers that follow simply become no-ops. While this can make debugging somewhat more difficult, it can dramatically reduce the number of lines needed in your onCreate method.

AQuery also makes invoking asynchronous HTTP requests very easy. It includes support for simple and multi-part POST operations and can accept data in binary, JSON, HTML, and XML formats. Separate support is included for images, where a single line can be used to download an image, cache it, and load the image into control.

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

  • Confusing name?

    by Richard Youngkin /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    I was initially confused by the name, thought it was a javascript library. Seemed odd to have a javascript library dedicated to android though...

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT

Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
Country/Zone:
State/Province/Region:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.