2014-01-26 39 views
0

我正在使用遊標加載器將本地sqlite數據庫查詢到列表視圖中。我想添加一些靜態單元格到列表視圖的頂部(靜態的,因爲它們沒有從數據庫查詢...值將被填充硬編碼)。對於iPhone開發人員來說,這有點像UITableView中的不同部分,您可以根據該部分的索引來填充該部分。反正有沒有在android中實現這個(使用CursorLoader時)?帶有靜態行的CursorLoader

編輯(我的代碼部分):

public void onCreate(Bundle savedInstanceState) { 
    mAdapter = new SimpleCursorAdapter(this, 
      R.layout.list_contacts, null, 
      DbContract.CONTACTS_FIELDS_DISPLAY, 
      new int[] { R.id.category_name, R.id.category_image }); 

     getLoaderManager().initLoader(0, null, this); 
    } 

    public Loader<Cursor> onCreateLoader(int id, Bundle args) { 

      return new CursorLoader(this, DbContract.URI_CATEGORIES, 
        DbContract.CATEGORIES_FIELDS, null, null, CategoriesTable.KEY_NAME); 
} 
+0

爲什麼不把這個數據放在數據庫中? –

+0

使用MergeCursor – pskink

+0

mohammed - 數據庫中的靜態行僅用於表示目的聽起來不太合適... – Ohad

回答

0

我會說使用CursorWrapper或MatrixCursor和MergeCursor在一起。您可以覆蓋/擴展CursorLoader loadInBackground。

return new CursorLoader(this, DbContract.URI_CATEGORIES, 
       DbContract.CATEGORIES_FIELDS, null, null, CategoriesTable.KEY_NAME) { 
    Cursor loadInBackground() { 
     .... do work here combining result of super.loadInBackground(); 
    };