title: Select items in ListView by id
body: <p>This is my code for the ListView, the thing is that i need to select the elements by id, not by position. 
  Can anyone help me out with this, i have tried using position but when i delete a listView a new ListView goes into that position which i don't want!</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
  // The data to show
  List&lt;Planet&gt; planetsList = new ArrayList&lt;Planet&gt;();
  PlanetAdapter aAdpt;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      initList();
  
      // We get the ListView component from the layout
      ListView lv = (ListView) findViewById(R.id.listView);
  
  
      // This is a simple adapter that accepts as parameter
      // Context
      // Data list
      // The row layout that is used during the row creation
      // The keys used to retrieve the data
      // The View id used to show the data. The key number and the view id must match
      //aAdpt = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, android.R.id.text1, planetsList);
      aAdpt = new PlanetAdapter(planetsList, this);
      lv.setAdapter(aAdpt);
  
      // React to user clicks on item
      lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  
          public void onItemClick(AdapterView&lt;?&gt; parentAdapter, View view, int position,
                                  long id) {
  
  
  
              if (position == 0) {
                  Toast.makeText(MainActivity.this, "Jello", Toast.LENGTH_SHORT).show();
                  Intent intent = new Intent(getApplicationContext(),PhotoActivity.class);
                  startActivity(intent);
              }
              if (position == 1) {
                  Toast.makeText(MainActivity.this, "Jello", Toast.LENGTH_SHORT).show();
              }
  
  
          }
      });
  
      // we register for the contextmneu
      registerForContextMenu(lv);
  }
  
  
  // We want to create a context Menu when the user long click on an item
  @Override
  public void onCreateContextMenu(ContextMenu menu, View v,
                                  ContextMenuInfo menuInfo) {
  
      super.onCreateContextMenu(menu, v, menuInfo);
      AdapterContextMenuInfo aInfo = (AdapterContextMenuInfo) menuInfo;
  
      // We know that each row in the adapter is a Map
      Planet planet =  aAdpt.getItem(aInfo.position);
  
      menu.setHeaderTitle("Options for " + planet.getName());
      menu.add(1, 2, 2, "Delete");
  
  }
  
  
  
  
  // This method is called when user selects an Item in the Context menu
  @Override
  public boolean onContextItemSelected(MenuItem item) {
      int itemId = item.getItemId();
      AdapterContextMenuInfo aInfo = (AdapterContextMenuInfo) item.getMenuInfo();
      planetsList.remove(aInfo.position);
      aAdpt.notifyDataSetChanged();
      return true;
  }
  
  
  private void initList() {
      // We populate the planets
  
      planetsList.add(new Planet("Work Gallery", 10));
      planetsList.add(new Planet("Buildings Gallery", 20));
      planetsList.add(new Planet("Miscellaneous", 30));
  
  
  }
  
  
  // Handle user click
  public void addPlanet(View view) {
      final Dialog d = new Dialog(this);
      d.setContentView(R.layout.dialog);
      d.setTitle("Add planet");
      d.setCancelable(true);
  
      final EditText edit = (EditText) d.findViewById(R.id.editTextPlanet);
      Button b = (Button) d.findViewById(R.id.button1);
      b.setOnClickListener(new View.OnClickListener() {
  
          public void onClick(View v) {
              String planetName = edit.getText().toString();
              MainActivity.this.planetsList.add(new Planet(planetName, 0));
              MainActivity.this.aAdpt.notifyDataSetChanged(); // We notify the data model is changed
              d.dismiss();
          }
      });
  
      d.show();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Planet.java</p>
  
  <pre><code>public class Planet {
  
  private String name;
  private Integer distance;
  private String descr;
  private int index;
  
  
  
  public Planet(String name, Integer distance) {
      this.name = name;
      this.distance = distance;
  }
  
  public Planet(String name, String descr) {
      this.name = name;
      this.descr = descr;
  }
  
  public Planet(String name, Integer distance, String descr, int idImg) {
      this.name = name;
      this.distance = distance;
      this.descr = descr;
      this.index = idImg;
  }
  
  
  public String getName() {
      return name;
  }
  public void setName(String name) {
      this.name = name;
  }
  public Integer getDistance() {
      return distance;
  }
  public void setDistance(Integer distance) {
      this.distance = distance;
  }
  public int getIdImg() {
      return index;
  }
  public void setIdImg(int idImg) {
      this.index = idImg;
  }
  </code></pre>
  
  <p>}</p>