loops - Android SQLite Display all records in Listview -


i have been on weekend , im @ wits end how return records in query listview

the following code works perfectly

public void displaycontact(string sitename) { final dbadapter db = new dbadapter(this); db.open();    cursor c = db.getasset6(sitename); int mx=0; string[] lvdata = new string[c.getcount()-1]; while (c.movetonext()) { lvdata[mx]=c.getstring(2) + "-" + c.getstring(1) + "-" + c.getstring(6); mx++;  } getactionbar().settitle("number of records = " + mx);      arrayadapter<string> adapter = new arrayadapter<string>(this,         r.layout.rowlayout, r.id.label, lvdata); setlistadapter(adapter);  }  public cursor getasset6(string strname) throws sqlexception  {      cursor mcursor =             db.query(true, database_table,                      new string[] {key_rowid,key_faultref,key_worknum,key_orignum,key_repby,key_repdattim,key_description},                      key_repby + " ?",                      new string[] { "%" + strname + "%" },                      null, null, null, null); if (mcursor != null) {         mcursor.movetofirst();     }     return mcursor;                            } 

the problem doesnt add first item in query (ie there 151 records in query puts 150 in listview missing first entry)

i sure c.movetofirst(); , statement have read every article can find on here , whatever combination try crashes when run query in app. running app using external database cant see whats causing crash in eclipse

can 1 of sql gurus me out driving me crazy

your appreciated

mark

i believe solution remove line from getasset6() method:

mcursor.movetofirst(); 

what happening, cursor being created , setting first row of results set. while loop defined as:

while (c.movetonext()) 

the condition of while loop evaluated first determine whether code follows should run. statement advances cursor second row before beginning adding lvdata[] array. hence first row getting skipped. removing movetofirst(), code should still work. movetonext() in while loop set cursor first row in first iteration , you'll data array. if cursor happens empty, movetonext() return false , nothing added array.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -