2015-10-13 67 views
0

我正在使用ActiveAndroid库。我需要获得按integer字段排序的我的对象列表。这里是我如何试图做到这一点:SQLite按整数值排序

public static List<Category> getCategories() { 
    try { 
     return new Select() 
      .all() 
      .from(Category.class) 
      .orderBy("NumInRow ASC") // NumInRow is my int field 
      .execute(); 
    } catch (Exception ignored) { 
     return null; 
    } 
} 

我是对的吗?

回答

0

是绝对的,你所做的是正确的方式来订购专栏,不管它是int还是某种其他数据类型都没关系。

例子:

public static List<Item> getAll(Category category) { 
     // This is how you execute a query 
     return new Select() 
      .from(Item.class) 
      .where("Category = ?", category.getId()) 
      .orderBy("Name ASC") 
      .execute(); 
    } 

Android活跃完全指南 Using Active Android