2013-07-26 39 views
1

運行查詢後。 Cursor有導致這樣的(我只給4在這裏)Android:從光標獲取數據

ID | Name | Topic| 
------------------ 
1 | A | Poster 
------------------ 
1 | B  | Poster 
------------------ 
2 | C  | Presentation 
------------------------- 
2 | D  | Presentation 

現在,所有我想告訴A & BC & D在列表視圖同一個小區。我怎樣才能做到這一點?

有什麼辦法可以像這樣獲取數據。

+0

你從哪裏得到數據,從SQLITE? – Oli

回答

0

您需要爲包含相同類型項目的listitem對象創建一個bean,然後爲該項目開發一個自定義列表視圖適配器以存檔該目標。

1

您可以將光標中的數據作爲字符串獲取,並在將它們保存在列表視圖中之前將其合併。

String example = (cursor.getString(0) + "," + cursor.getString(1)); cursor.moveToPosition(id);
example = example + (cursor.getString(0) + "," + cursor.getString(1));
ArrayList<String> listItems = new ArrayList<String>();
listItems.add(example);

0

GROUP BY Topic在您的SQL查詢和手動連接A,B。我不認爲你可以直接使用光標

1

你可以使用它爲我工作的代碼。

c.moveToFirst(); 
     if (c != null) { 
      do { 
       for (int i = 0; i < c.getColumnCount(); i++) { 

        Log.e("", "" + c.getString(i)); 
       } 
      }while (c.moveToNext()); 
     }