Build Status

An Android library inspire by AndroidQuery, bring chain style UI programming APi to UI development, aim to simplify android UI development.


I love the way develop android UI logic with AndroidQuery. Compare those code snippet

        ImageView tbView = (ImageView) view.findViewById(;
        if(tbView != null){




        TextView nameView = (TextView) view.findViewById(;
        if(nameView != null){

        TextView timeView = (TextView) view.findViewById(;

        if(timeView != null){
                long now = System.currentTimeMillis();
                timeView.setText(FormatUtility.relativeTime(now, content.getCreate()));

        TextView descView = (TextView) view.findViewById(;

        if(descView != null){

;;, content.getCreate())).visible();;

No nullpoint checking, no boring setter, short code is beautiful, isn't it?

Why another wheel?

AndroidQuery was created quite many years ago, try to cover most part of android development including ui,http request,rest and so on, which was good.

It's might a good open-box solution, but not good enough in all particular area, like url imageview, httprequest. I prefer using Picosso like library to provide better performance, for example.

butterknife bring DI to practical level, I believe it would be mainstream programming style,and it would need a better partner.

Despite of those, AndroidQuery has not update for quite long time.

So, I decided to create a library concentrate to simplify UI layer programming, and can be integrated well with other libraries.


 compile 'com.cocosw:query:0.+'


 compile 'com.cocosw.query:ext:0.+'

or just grab the jar file into your libs folder

Instant CocoQuery in your Activity or Fragment

    protected void onCreate(Bundle savedInstanceState) {
        q = new CocoQuery(this);

or in Fragment

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(layoutId(), null);
        CocoQuery q = new CocoQuery(getActivity(),v);

please NEVER keep CocoQuery instance into static field.

CocoQuery is NOT a

Async http request library

There are already tons of libraries doing this, you can feel free to choose the one you like, for example, chain style programming.

Image downloading library

I understand this is important for you, still, other libraries, like Picasso mentioned before can do this quite well.

If you want to bring use Picasso with CocoQuery style, like"http://img"); you can use ext artifact

Dependency & Compatibility


You can extend the class to adapt your custom view or 3rd party libraries.

Extend AbstractViewQuery
public class YourQuery extends AbstractViewQuery<DefaultQuery> {

   // constructor.....

     * Your own method to chain
     * @param resid the resid
     * @return self
    public T image(String url) {
        if (view instanceof ImageView) {
        return self();
Build CocoQuery

You only need to do this only one time, so onCreate in Application would be a ideal place

CocoQuery<YourQuery> q = new CocoQuery(activity);

You can also extend CocoQuery for other functions you need.


Apache License, Version 2.0


There are many codeline directly copy from AndroidQuery