java - Android Studio - Retrieve Data From SQLite Database and insert into Spinner -
i'm relatively new android studio sorry if quick fix
i'm trying retrieve column database put records column arraylist data in list can used populate spinner
the code have far follows;
try { //string sql = "insert inventory(name,amount,price,amountleft,weight) values('apple','30','1.99','28','1.01')"; //db.execsql(sql); cursor c = db.rawquery("select name inventory", null); if (c.getcount() == 0) { showmessage("welcome!", "please add items inventory"); } list inventorylist = new arraylist(); integer i=0; if(c.movetofirst()) { { inventorylist.add(i, c.getcolumnindex("1")); i+=1; }while(c.movetonext()); } c.close(); db.close(); flav1invspinner = (spinner)findviewbyid(r.id.combo_invchoice1); arrayadapter<string> dataadapter = new arrayadapter<string>(this, android.r.layout.simple_spinner_item, inventorylist); dataadapter.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item); flav1invspinner.setadapter(dataadapter); } catch(exception e) { showmessage("error", "cannot connect database \n" + e.getmessage() ); }
however combo box displaying -1 when emulator running i'd expect display 'apple'
any suggestions i've done wrong / missed
thanks
figured out, didn't need c.getcolumnindex
it needs c.getstring(0));
works treat now!
Comments
Post a Comment