arraylist - how to change listview data on spinner selection? -


i have spinner , listview in view. data coming in both sqlite . spinner data coming category table(cid, cname) cname show in spinner , listview data items table(iid, iname, cid) iname show in listview. cid foreign key in items table .when spinner selection change want change listview data.this have done far.. below spinner cname populated sqlite

      spinner1.setonitemselectedlistener(new adapterview.onitemselectedlistener() {         @override         public void onitemselected(adapterview<?> parent, view view, final int position, long id) {                                                    dbrepo = new dbrepo(getapplicationcontext());                                 string pos = (string) parent.getselecteditemposition();                           string cid =   dbrepo.getid(pos);             toast.maketext(getapplicationcontext(), cid, toast.length_long).show();             final arraylist<support> list = dbrepo.getitems(cid);                  adapter = new custom(category.this, r.layout.view_entry, list);                  lv.setadapter(adapter);                                  adapter.notifydatasetchanged(); 

this code cid of selected item in spinner

public  string getid(string selected) {     sqlitedatabase db = this.getreadabledatabase();     string query = "select cid catogeries cname=\"" + selected+ "\"";     cursor c = db.rawquery(query, null);     string s = null;      if (c.movetofirst()) {         while (c.movetonext()) {             s = c.getint(c.getcolumnindex("cid"));          }     }     c.close();     db.close();     log.e("cid", " " + s);      return s; } 

this method data in listview db

 public arraylist<support> getitems(string cid){    arraylist<support> list = new arraylist<support>();     sqlitedatabase db = this.getreadabledatabase();   // cursor c = db.query(table_item, new string[]{key_iid, key_iname, key_cid}, key_cid + "=?", new string[]{cid}, null, null, null,null);     string select = "select * items_table cid = "+cid;     cursor c = db.rawquery(select, null);     string res;     int j = c.getcolumnindex(support.key_iname);     if(c.movetofirst()){         {             support item = new support();                     item.setitemid(c.getstring(0));                     item.setitemname(c.getstring(1));                     item.setcategoryid(c.getstring(2));                     list.add(item);         }while (c.movetonext());     }     c.close();     db.close();     return list; } 

now cid showing in toast after passing cid getitems() items nothing showing in listview.cid showing in getitems() in log

   public arraylist<support> getitems(string cid) {     arraylist<support> itemlist = new arraylist<support>();     sqlitedatabase db = this.getreadabledatabase();     log.e("cid is", cid);     string selectquery = "select * " + table_item;     cursor c = db.rawquery(selectquery, null);     if (c != null) {         while (c.movetonext()) {             support item = new support();             item.setitemid(c.getstring(0));             item.setitemname(c.getstring(1));             item.setcategoryid(c.getstring(2));             itemlist.add(item);         }     }     c.close();     db.close();     return itemlist; } 

the above code showing items without passing cid when pass cid listview showing empty , no error showing in logcat

finally resolved issue because of space after cid using trim function while storing data fetched webservice sqlite has done me

public arraylist<support> getitems(string cid){    arraylist<support> list = new arraylist<support>();    sqlitedatabase db = this.getreadabledatabase();    cursor cursor = database.rawquery(select * items_table cid =? ",  new string[]  {cid}, null);     support item = new support( );  if(cursor!=null) {   while(cursor.movetonext()) {    string id= cursor.getstring(cursor.getcolumnindexorthrow(your_databasehelper.id_column));    // same others    item.add(id);    list.add(item); } }     cursor.close();     db.close();     return list; }         

Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -