Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How would I be able to display a query result in a textview, when I try to display it, all that shows it "android.database.sqlite.SQLiteCursor@457436". Thanks!


What I have tried:

I have tried different variations of displaying the query, but none of them work.
Posted
Updated 23-Oct-19 22:03pm
Comments
Mohibur Rashid 23-Oct-19 17:47pm    
How do you display any text in android?
Richard MacCutchan 24-Oct-19 3:21am    
You are obviously trying to display some 'object' reference, rather than the actual results of your query. However, since you have not included the actual code extract in your question it is impossible to guess anything more.

1 solution

The TextView showing `android.database.sqlite.SQLiteCursor@457436` indicates that it is using the Cursor's (inherited/default) toString method which shows the object name and the pointer to the object.

Instead of using

yourTextView.setText(your_cursor);
(or perhaps the method that returns the Cursor e.g. yourTextView.setText(yourGetDataMethod());)

You need to do something similar to :-

your_cursor = yourGetDataMethod();
if (your_cursor.moveToFirst() ) {
    yourTextView.setText(your_cursor.getString(your_cursor.getColumnIndex("your_column_name_to_get_the data_from");
} else {
    yourTextView.setText("Ooops no data extracted");
}
your_cursor.close();


This moves the Cursor from the position before the first row, to the first row of the Cursor if there is a row.

and then (if there are any rows) it extracts the data, as a String, from the respective column of the Cursor.

If there aren't any rows then the TextView will display the message that indicates this.
Finally the Cursor is closed.

Note that in the absence of any indication of the names used the above uses names that give an indication of the where the name would be obtained from.
i.e. your_ indicates such a usage.
Note the above is in-principle code, it has not been run or tested and may therefore contain some errors.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900