In today’s post we continue our Android blog series for Mobile Services. Here are the other posts in the series.
Today we will talk about the query model in the Android client. In our C# client we were lucky to be able to lean on LINQ, but after some research we found that there is no out-of-the-box equivalent in the Android platform. I’m glad to stand corrected here: please let me know in the comments if we missed something.
Given that, we decided to implement our own fluent query API that supports the same richness that you get with LINQ, so it deserves a thorough writeup. We’ll assume we’re working with our same reference type we used in our last tutorial, but we’ve added a field or two to make things more interesting to query against:
~~~ java
public class Droid {
@com.google.gson.annotations.SerializedName("id")
private Integer mId;
@com.google.gson.annotations.SerializedName("name")
private String mName;
@com.google.gson.annotations.SerializedName("weight")
private Float mWeight;
@com.google.gson.annotations.SerializedName("numberOfLegs")
private Integer mNumberOfLegs;
@com.google.gson.annotations.SerializedName("numberOfWheels")
private Integer mNumberOfWheels;
@com.google.gson.annotations.SerializedName("manufactureDate")
private Date mManufactureDate;
@com.google.gson.annotations.SerializedName("canTalk")
private Boolean mCanTalk;
public Integer getId() { return mId; }
public final void setId(Integer id) { mId = id; }
public String getName() { return mName; }
public final void setName(String name) { mName = name; }
public Float getWeight() { return mWeight; }
public final void setWeight(Float weight) { mWeight = weight; }
public Integer getNumberOfLegs () { return mNumberOfLegs; }
public final void setNumberOfLegs(Integer numberOfLegs) {
mNumberOfLegs = numberOfLegs;
}
public Integer getNumberOfWheels() { return mNumberOfWheels; }
public final void setNumberOfWheels(Integer numberOfWheels) {
mNumberOfWheels = numberOfWheels;
}
Read More