title: how to change listview data on spinner selection?
body: <p>i have a spinner and a listview in a view. data is coming in both from sqlite .
  spinner data is coming from category table(Cid, Cname) Cname is to show in spinner and listview data is from Items table(Iid, Iname, Cid) Iname is to show in listview. cid is foreign key in items table .when spinner selection change i want to change listview data.this is what i have done so far..
  below is my spinner with Cname populated from sqlite </p>
  
  <pre><code>      spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView&lt;?&gt; 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&lt;Support&gt; list = dbRepo.getItems(cid);
  
                  adapter = new Custom(Category.this, R.layout.view_entry, list);
  
                  lv.setAdapter(adapter);                  
                 adapter.notifyDataSetChanged();
  </code></pre>
  
  <p>this is the code to get cid of selected item in spinner </p>
  
  <pre><code>public  String getId(String selected) {
      SQLiteDatabase db = this.getReadableDatabase();
      String query = "SELECT Cid from Catogeries where 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;
  }
  </code></pre>
  
  <p>this is the method to get data in listview from db </p>
  
  <pre><code> public ArrayList&lt;Support&gt; getItems(String cid){
     ArrayList&lt;Support&gt; list = new ArrayList&lt;Support&gt;();
      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 * from items_table where Cid = "+cid;
      Cursor c = db.rawQuery(select, null);
      String res;
      int j = c.getColumnIndex(Support.KEY_INAME);
      if(c.moveToFirst()){
          do {
              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;
  }
  </code></pre>
  
  <p>now cid is showing in toast but after passing cid to getitems() to get items nothing showing in listview.cid is showing in getItems() in log</p>
  
  <pre><code>   public ArrayList&lt;Support&gt; getItems(String cid) {
      ArrayList&lt;Support&gt; itemlist = new ArrayList&lt;Support&gt;();
      SQLiteDatabase db = this.getReadableDatabase();
      Log.e("CID is", cid);
      String selectQuery = "SELECT * FROM " + 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;
  }
  </code></pre>
  
  <p>the above code is showing items without passing cid but when i pass cid listview is showing empty and their is no error showing in logcat</p>
  
  <p>finally resolved my issue that was because of a space after cid using trim function while storing data fetched from webservice to sqlite has done for me</p>