2015-10-13 70 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