How do I get the value stored in a column using Cursor?

1

I have a cursor that receives all the data from my table after I use the Simcurscursoradapter to put it in a listview.

I wanted to know if with this same cursor I could get a data from a row and put it in a textview.

    
asked by anonymous 04.07.2017 / 23:06

1 answer

1

For each data type a table column saves the implementation of the Cursor interface a method to get its value.

To get the value stored in a column of type string, you must use the getString ( int column) .

These methods use an integer (index) to identify the column.

You can get this index through the column name using the getColumnIndexOrThrow (String columnName) .

So, to get the value stored in a column of type name string XXX you should use:

String valor = cursor.getString(cursor.getColumnIndexOrThrow("XXX"));
    
04.07.2017 / 23:38