android - Displaying a Cursor as a return value from a method-SQLite -


I am trying to use the following method to calculate the total values ​​in a certain column in my DB .

  / ** * The method which gives the level of average meditation * in DB * @ return * / public cursor getTotalOfAllMedLevels () {SQLiteDatabase db = this.getWritableDatabase () ; String query = "SELECT SUM (avgmeditation) FROM" + TABLE_SCORE; Cursor c = db.rawQuery (query, empty); Return c; }  

Again, I am trying to display the value of the return value within a TextView (avgMed) method in a different action:

  Display AverageOfAllMedValues ​​() {cursor c = db.getTotalOfAllMedLevels (); AvgMed.setText ("" + c); }  

But get the following output in the TextView:

  android.database.sqlite.SQLiteCursor@529db063  

Is this a way to convert output to an int value, or alternatively how can I change my code to give an int output I want.

Edit: Current database creation and structure:

  Expands SQLiteOpenHelper to public class databaseHalf {// database version personal constant final end DATABASE_VERSION = 10; // Database Name Private Last Fixed String DATABASE_NAME = "Attention Database"; // Contact table name personal constant last string TABLE_SCORE = "score"; // contact table column name personal constant last string COL_SESSION = "sessionid"; Private static last string COL_GAMETITLE = "sports"; Private static last string COL_NAME = "name"; Private static last string COL_MED = "avgmeditation"; Private static final string COL_MAX = "max minutes"; Private static final string COL_AVGATT = "avgattention"; Private static final string COL_MAXATT = "maximum"; Private static final string COL_SCORE = "score"; Private static final string COL_DATE = "date"; / ** * Constructor * * @ Ultimate Context * / Public Database Helper (Reference Reference) {Super (Reference, DatabaseNN, Blank, DatabaseBens); } / ** * method that creates the database / / override the creation of the public at zero (SQLiteDatabase DB) {string CREATE_TABLE_SCORE = "create table" + TABLE_SCORE + "(" + COL_SESSION + "STRING primary key," + COL_GAMETITLE + "STRING, "+ COL_NAME +" INTEGER, "+ COL_MAX +" INTEGER, "+ COL_AVGATT +" INTEGER, "+ COL_MAXATT +" INTEGER, "+ COL_SCORE +" INTEGER, "+ COL_DATE +" STRING "+") "; Db.execSQL (CREATE_TABLE_SCORE); }   

The cursor is like an array in this. You have to do something like this:

  Public Waste Demonstration AllModewells () {Cursor C = DB.GostolaOff All Models (); If (c! = Null & amp; amp; c.moveToFirst) {avgMed.setText ("" + c.getInt (0)); }}  

Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -