2012-03-08 86 views
3

我有一个方法,我传递一个id,然后想要找到该表中匹配该id的行,并返回一个字符串是colLabel行:sqlite Android的 - 如何获得特定列/行的价值

public String getIconLabel(int id){ 
     String label; 
     String selectQuery = "SELECT "+colL" FROM " + allIcons + " WHERE " +colIconID + "="+id; 

     SQLiteDatabase db = this.getReadableDatabase(); 
     Cursor cursor = db.rawQuery(selectQuery, null); 

     label = //HELP 

     return label; 

    } 

我不清楚至于如何将标签设置为所选行的特定列?

请帮助

回答

5
if (null != cursor && cursor.moveToFirst()) { 
    label = cursor.getString(cursor.getColumnIndex(COLUMN_ID)); 
} 
4
if(cursor != null) 
{ 
cursor.moveToFirst(); 
String label = cursor.getString(0); 
} 

0参数表示的列索引。请参阅此link