2011-08-05 43 views
0

我試圖綁定一個客戶的ContentProvider我的活動,擁有一個GridView我怎麼一個GridView綁定到一個自定義的ContentProvider

String[] projection = { SAppsDatabase.ID, SAppsDatabase.COL_APP_TITLE}; 
    String[] uiBindFrom = { SAppsDatabase.COL_APP_TITLE }; 
    int[] uiBindTo = { R.id.title }; 

    Cursor apps = managedQuery(
      MyProvider.CONTENT_URI, projection, null, null, null); 

    GridView gridview = (GridView) findViewById(R.id.gridview); 

    CursorAdapter adapter = new SimpleCursorAdapter(getApplicationContext(), R.layout.grid_app_list, apps, 
      uiBindFrom, uiBindTo); 

    gridview.setAdapter(adapter); 

這是行不通的。

我設法通過與上面相同的方式將它綁定到ListActivity,並設置: setListAdapter(adapter);

回答

1

顧名思義它的觀點

GridView is a ViewGroup that displays items in a two-dimensional, scrollable grid. 
The grid items are automatically inserted to the layout using a ListAdapter. 

一個網格,但你提供它的光標適配器,它並沒有太大的意義上,這將不是一個GridView工作。

如果你想提供一個自定義適配器,那麼你將不得不延長適配器和返回適配器中查看內容看看這個sample

+0

謝謝拉維。我想我可以解決這個問題。看來我需要將ContentProvider包裝在BaseAdapter中。 – andydev

+0

你能解決這個問題嗎? – bluefalcon

+0

當我回到開發的這一部分,並實現包裝,我會在這裏發佈 – andydev

相關問題