Android Spinner is empty -


there no errors in code. works fine except spinner isn't populated database expected. rather, empty. please help!!

retrieve records sqlite:

// contacts  public list getallnames() {  list names = new arraylist();  // select query string selectquery = "select  * " + table_name;  sqlitedatabase db = this.getreadabledatabase(); cursor cursor = db.rawquery(selectquery, null);  // looping through rows , adding list if (cursor.movetofirst()) {     {         names.add(cursor.getstring(1));     } while (cursor.movetonext()); }  // closing connection db.close();  // returning contacts return names; 

}

load spinner:

private void loadspinnerdata() {  // database handler  databasehandler db = new databasehandler(getapplicationcontext());  // spinner drop down elements list<string> contacts = db.getallnames();  // creating adapter spinner arrayadapter<string> dataadapter = new arrayadapter<string>(this,         android.r.layout.simple_spinner_item, contacts);  // drop down layout style - list view radio button dataadapter         .setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item);  // attaching data adapter spinner spinner.setadapter(dataadapter); 

}

i guess needs minor tweak somewhere, don't understand where. in advance!


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -