Sqlite Android - how to get the value of a specific column / row

I have a method by which I pass an ID and then I want to find the row in this table that matches the ID and returns a row that is the colLabel of that row:

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;

    }

      

Not clear how to set the label as this column of the selected row?

please, help

+3


source to share


2 answers


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

      



+5


source


if(cursor != null)
{
cursor.moveToFirst();
String label = cursor.getString(0);
}

      



The 0 parameter represents your column index. See Link.

+4


source







All Articles