How to list all the rows in a table using SQLite in android studio using cursor -


i using android studio handle database sqlite. need list items in table items in listview..how can it. know how first item using cursor.movetofirst() this

public rows getrows(){     string query = "select * "+table_name;     sqlitedatabase db = getwritabledatabase();     cursor = db.rawquery(query,null);     rows rows;     if(cursor.movetofirst()){                 rows.setcol1(cursor.getstring(0));                 rows.setcol2(cursor.getstring(1));                 rows.setcol3(cursor.getstring(2));                 cursor.close();             }     else{                rows=null;         }     return rows; } 

can use cursor.movetonext() if yes please give me code....

use this,

public arraylist<rows> getrows(){     string query = "select * "+table_name;     sqlitedatabase db = getwritabledatabase();     cursor = db.rawquery(query,null);     arraylist<rows> list=new arraylist<rows>();      while(cursor.movetonext()){           rows row=new rows();           row.setcol1(cursor.getstring(0));           row.setcol2(cursor.getstring(1));           row.setcol3(cursor.getstring(2));           list.add(row);      }      cursor.close();     db.close();     return list; } 

Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -