2015-10-04 75 views
3

我想從數據庫中獲取ID和partyname,並返回兩者,並希望顯示listitem,但點擊的listitem ID應傳遞給另一個活動,而不是partyname,快照:「http://i.stack.imgur.com/ZFiN9.jpg」。我想獲得ID和partyname,並且想要返回兩者。

public ArrayList<String> getPartyName(){ 

    ArrayList<String> partylist = new ArrayList<String>(); 
    SQLiteDatabase db = this.getDB(); 
    Cursor c; 

    try { 
     c = db.rawQuery("SELECT * FROM RECORDS" , null); 

     if(c == null) return null; 

     String PARTY_NAME; 
     c.moveToFirst(); 
     do {    

      PARTY_NAME = c.getString(3); 
      partylist.add(PARTY_NAME); 
      [![enter image description here][1]][1] 

     } while (c.moveToNext()); 
     c.close(); 
     db.close(); 
    } catch (Exception e) { 
     Log.e("login", e.getMessage()); 
    } 


    return partylist; 

} 

回答

0

改變你的查詢是這樣的:

c = db.rawQuery("SELECT id FROM RECORDS" , null); 

與您的ID列的名稱替換ID。