title: How to remove item from listview populated by a database but don’t remove from the database
body: <p>I have two activities. The first contains a list of strings that will be populated onClick from rows in a database, the second activity displays all rows in a database from which you pick from.</p>
  
  <p>The idea is to pick 15 players for a sports team from the players on the database.</p>
  
  <p>What I want to do is remove the player that has been picked from the list in the second activity once it has been clicked i.e. so I cannot pick the same player twice.</p>
  
  <p>Here are my activities:</p>
  
  <pre><code>public class PickTeamActivity extends Activity {
  
  ListView listView;
  String[] values;
  String context;
  Bundle extras;
  public static final String PREFS = "examplePrefs";
  
  Button finish;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_pickteam);
  
      SharedPreferences exmaple = getSharedPreferences(PREFS, 0);
      context = exmaple.getString("teamName", "cant find team");
  
      extras = getIntent().getExtras();
  
      // Get ListView object from xml
      listView = (ListView) findViewById(R.id.listViewPlayers);
  
      // Defined Array values to show in ListView
      values = new String[] { "No.1 ", "No.2 ", "No.3 ", "No.4 ", "No.5 ",
              "No.6 ", "No.7 ", "No.8 ", "No.9 ", "No.10 ", "No.11 ",
              "No.12 ", "No.13 ", "No.14 ", "No.15 "
  
      };
  
      ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this,
              android.R.layout.simple_list_item_1, android.R.id.text1, values);
      // Assign adapter to ListView
      View v = getLayoutInflater().inflate(R.layout.footer_view, null);
      listView.addFooterView(v);
      listView.setAdapter(adapter);
  
      finish = (Button) findViewById(R.id.btn_finishPicking);
      finish.setOnClickListener(new View.OnClickListener() {
          public void onClick(View view) {
  
              Intent i = new Intent(PickTeamActivity.this, OptionsActivity.class);
              startActivity(i);  
          }
      });
      listView.setOnItemClickListener(new OnItemClickListener() {
  
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                  int position, long id) {
  
              // ListView Clicked item index
              int itemPosition = position;
  
              // ListView Clicked item value
              String itemValue = (String) listView
                      .getItemAtPosition(position);
  
              // Show Alert
              Toast.makeText(
                      getApplicationContext(),
                      "Position :" + itemPosition + "  ListItem : "
                              + itemValue, Toast.LENGTH_LONG).show();
  
              // .................................................................................
  
              Bundle passdata = new Bundle();
              passdata.putInt("position", itemPosition);
              passdata.putString("value", itemValue);
  
              Intent passIntent = new Intent(PickTeamActivity.this,
                      ViewMatchPlayersActivity.class);
              passIntent.putExtras(passdata);
              startActivityForResult(passIntent, 0);
  
          }
  
      });
  
  
  }
  
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
  
      finish.setOnClickListener(new View.OnClickListener() {
          public void onClick(View view) {
  
              Intent i = new Intent(PickTeamActivity.this, OptionsActivity.class);
              startActivity(i);  
          }
      });
      //TODO handle here. 
  
      Bundle b = data.getExtras();
     // ArrayList&lt;Integer&gt; removeList  = new ArrayList&lt;Integer&gt;();
  
      int i = b.getInt("row");
      int p = b.getInt("previous_pos");
      String v = b.getString("previous_val");
      MySQLiteAdapters regadapter = new MySQLiteAdapters(this);
      Cursor c = regadapter.queryRecord(i);
  
      if (c.moveToFirst()) {
          do {
              values[p] = v + ": " + c.getString(0) + " " + c.getString(1);
          } while (c.moveToNext());
      }
  
      ArrayList&lt;Integer&gt; removeList  = new ArrayList&lt;Integer&gt;();
      removeList.add(i);
  
      ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this,
              android.R.layout.simple_list_item_1, android.R.id.text1, values);
      View view = getLayoutInflater().inflate(R.layout.footer_view, null);
      listView.addFooterView(view);
      listView.setAdapter(adapter);
      listView.setOnItemClickListener(new OnItemClickListener() {
  
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                  int position, long id) {
  
              // ListView Clicked item index
              int itemPosition = position;
  
              // ListView Clicked item value
              String itemValue = (String) listView
                      .getItemAtPosition(position);
  
              // Show Alert
              Toast.makeText(
                      getApplicationContext(),
                      "Position :" + itemPosition + "  ListItem : "
                              + itemValue, Toast.LENGTH_LONG).show();
  
              // .................................................................................
  
              Bundle passdata = new Bundle();
              passdata.putInt("position", itemPosition);
              passdata.putString("value", itemValue);
  
              Intent passIntent = new Intent(PickTeamActivity.this,
                      ViewMatchPlayersActivity.class);
              passIntent.putExtras(passdata);
              startActivityForResult(passIntent, 0);
  
          }
  
      });
  }
  
  public void onBackPressed()
  {
      Intent i = new Intent(PickTeamActivity.this, OptionsActivity.class);
      startActivity(i);  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>public class ViewMatchPlayersActivity extends Activity {</p>
  
  <pre><code>ListView nameList;
  MySQLiteAdapters adapter_ob;
  MySQLiteHelper helper_ob;
  SQLiteDatabase db_ob;
  Button registerBtn;
  Cursor cursor, cursor2, cursor3;
  String val, team;
  int pos;
  String[] removeList;
  public static final String PREFS = "examplePrefs";
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_view_match_players);
      nameList = (ListView) findViewById(R.id.listView2);
      adapter_ob = new MySQLiteAdapters(this);
  
      SharedPreferences exmaple = getSharedPreferences(PREFS, 0);
      team = exmaple.getString("teamName", "cant find team");
      Bundle extras = getIntent().getExtras();
  
      pos = extras.getInt("position");
      val = extras.getString("value");
  
      String[] from = { helper_ob.KEY_FNAME, helper_ob.KEY_LNAME,
              helper_ob.KEY_POSITION, helper_ob.KEY_TEAMNAME };
      int[] to = { R.id.tv_fname, R.id.tv_lname, R.id.tv_position,
              R.id.tv_teamName };
      cursor = adapter_ob.queryName(team);
      SimpleCursorAdapter cursorAdapter = new SimpleCursorAdapter(this,
              R.layout.row, cursor, from, to);
  
      nameList.setAdapter(cursorAdapter);
      nameList.setOnItemClickListener(new OnItemClickListener() {
  
          @Override
          public void onItemClick(AdapterView arg0, View arg1, int arg2,
                  long arg3) {
              //ArrayList&lt;Integer&gt; removeList  = new ArrayList&lt;Integer&gt;();
              Cursor listCursor = (Cursor) arg0.getItemAtPosition(arg2);
              int playerRecord = listCursor.getInt(listCursor
                      .getColumnIndex("p_id"));
              //removeList.add(playerRecord);
  
              adapter_ob.playerPicked(playerRecord, "YES", pos + 1);
  
              Bundle passdata = new Bundle();
              passdata.putInt("row", playerRecord);
              passdata.putInt("previous_pos", pos);
              passdata.putString("previous_val", val);
  
              Intent passIntent = getIntent();
              passIntent.putExtras(passdata);
              setResult(RESULT_OK, passIntent);
              finish();
          }
      });
   }
  }
  </code></pre>
  
  <p>As you can see I am getting the list of players from the database here:</p>
  
  <pre><code> cursor = adapter_ob.queryName(team);
  </code></pre>
  
  <p>I want to somehow edit that list and remove the records that have selected previously using the row ID which I get here:</p>
  
  <pre><code>int playerRecord = listCursor.getInt(listCursor
                  .getColumnIndex("p_id"));
  </code></pre>
  
  <p>Thanks!</p>