title: Getting row id from database by clicking listview after deleting record
body: <p>I have created a database with 5 columns id , name , date , month and year.
  it is getting created perfectly, i am able to put it in a list view.
  Now the problem is that when i delete a record from the database. I am not
  able to get the correct row id to work on(delete or edit it).because the list view does not point to the database , only shows the strings from there in a list view.</p>
  
  <p>is there a way that after i remove a record i can still get the correct row id to work on.
  i want to get the row id of the record when clicked in the list view..</p>
  
  <p>Get data function used in database to send the 5 items to the display activity</p>
  
  <pre><code>public ArrayList&lt;String&gt; getData() {
  
      String[] columns = new String[] { KEY_ROWID, KEY_NAME, KEY_DATE,
              KEY_MONTH, KEY_YEAR };
  
      Cursor c = db.query(DATABASE_TABLE, columns, null, null, null, null,
              null);
      String result = "";
  
      int iRow = c.getColumnIndex(KEY_ROWID);
      int iName = c.getColumnIndex(KEY_NAME);
      int iDate = c.getColumnIndex(KEY_DATE);
      int iMonth = c.getColumnIndex(KEY_MONTH);
      int iYear = c.getColumnIndex(KEY_YEAR);
      ArrayList&lt;String&gt; string_array = new ArrayList&lt;String&gt;();
      for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
          result = c.getString(iRow) + " " + c.getString(iName) + "\t\t"
                  + c.getString(iDate) + "\t\t" + c.getString(iMonth)
                  + "\t\t" + c.getString(iYear) + "\n";
          string_array.add(result);
  
      }
      return string_array;
  }
  </code></pre>
  
  <p>call for string array in the display activity</p>
  
  <pre><code> ArrayList&lt;String&gt; data = db.getData();
      ArrayAdapter&lt;String&gt; arrayAdapter = new ArrayAdapter&lt;String&gt;(this,
              android.R.layout.simple_list_item_1, data);
      lv.setAdapter(arrayAdapter);
      lv.setOnItemClickListener(this);
  </code></pre>
  
  <p>Getting the row id after first elements from database are deleted</p>
  
  <pre><code>  public long getFROWID() {
      String[] columns = new String[] { KEY_ROWID, KEY_NAME, KEY_DATE,
              KEY_MONTH, KEY_YEAR };
  
      Cursor c = db.query(DATABASE_TABLE, columns, null, null, null, null,
              null);
      c.moveToFirst();
      int iRow = c.getColumnIndex(KEY_ROWID);
      ROWID = c.getString(iRow);
      long value = Long.parseLong(ROWID);
      return value;
  }
  </code></pre>
  
  <p>Function in the database class to get the first row id after record is deleted</p>
  
  <pre><code>  @Override
  public boolean onItemLongClick(AdapterView&lt;?&gt; parent, View listview,
          int position, long id) { 
      IMPID = db.getFROWID() + id;
      openContextMenu(lv);
      return true;
  }
  </code></pre>
  
  <p>Update using simple adapter</p>
  
  <pre><code>  String[] from = { BdayDatabase.KEY_NAME };
      int[] to = { R.id.item_name };
  
      List&lt;HashMap&lt;String, String&gt;&gt; listinfo = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
      listinfo.clear();
  
          HashMap&lt;String, String&gt; hm = new HashMap&lt;String, String&gt;();
          hm.put("name" , BdayDatabase.KEY_NAME);
          listinfo.add(hm);
  
  
      SimpleAdapter adapter = new SimpleAdapter(this, listinfo, R.layout.item_layout, from, to);
      lv.setAdapter(adapter);
  </code></pre>
  
  <p>Thank you in advance</p>