title: How to remove an item and refresh the listview
body: <p>I have an listview in my program. In that i populated the values from the database and displayed. Iam using context menu to edit,delete items in listview. if i chose delete in the context menu it deletes the item in the database but i did'nt removed the item from the listview. What iam doing wrong here. Please help me if anybody knows.</p>
  
  <p>Retrieve method:</p>
  
  <pre><code>public void retrievedb() {
          strquery = "SELECT * FROM api_settings";
          Cursor mCursor = (MainscreenActivity.JEEMAAndroSMSDB).rawQuery(
                  strquery, null);
          if (mCursor.getCount() != 0) {
              mCursor.moveToLast();
              for (int i = mCursor.getCount() - 1; i &gt;= 0; i--) {
                  dbid = mCursor.getString(0);
                  dbapiname = mCursor.getString(1);
                  dbURL = mCursor.getString(2);
                  dbUnameVar = mCursor.getString(3);
                  dbUnameVal = mCursor.getString(4);
                  dbPwdVar = mCursor.getString(5);
                  dbPwdVal = mCursor.getString(6);
                  dbsendername = mCursor.getString(7);
                  dbdestinationvar = mCursor.getString(8);
                  dbmsgvariable = mCursor.getString(9);
                  dbchars = mCursor.getString(10);
              }
          }
  
          if ((dbapiname == null) || (dbURL == null) || (dbUnameVar == null)
                  || (dbUnameVal == null) || (dbPwdVar == null)
                  || (dbPwdVal == null) || (dbsendername == null)
                  || (dbdestinationvar == null) || (dbmsgvariable == null)
                  || (dbchars == null)) {
  
              tvText = (TextView) findViewById(android.R.id.text1);
              tvText.setVisibility(1);
          } else {
              adapter = new ArrayAdapter&lt;Settingsmodel&gt;(this,
                      android.R.layout.simple_list_item_1, listItems);
              tvText = (TextView) findViewById(android.R.id.text1);
              tvText.setVisibility(View.GONE);
              strquery = "SELECT ID,API_Name FROM api_settings";
              mCursor = (MainscreenActivity.JEEMAAndroSMSDB).rawQuery(strquery,
                      null);
              if (mCursor.getCount() != 0) {
                  mCursor.moveToFirst();
                  do {
                      dbid = mCursor.getString(0);
                      dbapiname = mCursor.getString(1);
                      listItems.add(new Settingsmodel(dbapiname, dbid));
                      adapter.notifyDataSetChanged();
                  } while (mCursor.moveToNext());
              }
          }
      }
  </code></pre>
  
  <p>Context Menu:</p>
  
  <pre><code>@Override
      public void onCreateContextMenu(ContextMenu menu, final View v,
              ContextMenuInfo menuInfo) {
          if (v.getId() == android.R.id.list) {
              AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
              Settingsmodel selectedValue = (Settingsmodel) getListAdapter()
                      .getItem(info.position);
              String tempo = selectedValue.getSpinnerText();
              menu.setHeaderTitle(tempo);
              String[] menuItems = getResources().getStringArray(R.array.menu);
              for (int i = 0; i &lt; menuItems.length; i++) {
                  menu.add(Menu.NONE, i, i, menuItems[i]);
              }
  
          }
      }
  
      @Override
      public boolean onContextItemSelected(MenuItem item) {
          AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item
                  .getMenuInfo();
          int menuItemIndex = item.getItemId();
          String[] menuItems = getResources().getStringArray(R.array.menu);
          String menuItemName = menuItems[menuItemIndex];
          Settingsmodel selectedValue = (Settingsmodel) getListAdapter().getItem(
                  info.position);
          String temp0 = selectedValue.getSpinnerText();
          String temp1 = selectedValue.getValue();
          int id = Integer.parseInt(temp1);
          if (menuItemName.equalsIgnoreCase("Set as Default")) {
              ContentValues values = new ContentValues();
              values.put(MainscreenActivity.COL_Set_Default, value);
              MainscreenActivity.JEEMAAndroSMSDB.update(
                      MainscreenActivity.TABLE_Name, values, "ID=" + id, null);
              values.put(MainscreenActivity.COL_Set_Default, 0);
              Toast.makeText(getBaseContext(), temp0 + " is set as Default",
                      Toast.LENGTH_LONG).show();
              MainscreenActivity.JEEMAAndroSMSDB.update(
                      MainscreenActivity.TABLE_Name, values, "ID!=" + id, null);
          }
  
          if (menuItemName.equalsIgnoreCase("Delete")) {
              MainscreenActivity.JEEMAAndroSMSDB.delete(
                      MainscreenActivity.TABLE_Name, "ID=" + id, null);           
              Toast.makeText(getBaseContext(), "API Deleted Successfully",
                      Toast.LENGTH_SHORT).show(); 
              retrievedb();
          }
  
          return true;
      }
  </code></pre>