title: Android - Getting the id of a ListView item [Special Case]
body: <p>In my DB class have a method that returns a Cursor. the cursor will contain data from different tables:</p>
  
  <pre><code>public Cursor fetchFavTitles() {
      return myDataBase.rawQuery("SELECT rowid as _id, title, fav FROM table1 " +
                                  "WHERE fav = 1 UNION ALL " +
              "SELECT rowid as _id, title, fav FROM table2 WHERE fav = 1 UNION ALL " +
              "SELECT rowid as _id, title, fav FROM table3 WHERE fav = 1 UNION ALL " +
              "SELECT rowid as _id, title, fav FROM table4 WHERE fav = 1 UNION ALL " +
              "SELECT rowid as _id, title, fav FROM table5 WHERE fav = 1 UNION ALL " +
              "SELECT rowid as _id, title, fav FROM table6 WHERE fav = 1", null);
  
  }
  </code></pre>
  
  <p>Then, I use a <code>SimpleCursorAdapter ca</code> to attach the <code>Cursor</code> to a <code>ListView lv</code> :</p>
  
  <pre><code>Cursor cursor = myDbHelper.fetchTitles(c);
  String[] columns = {cursor.getColumnName(1)}; 
  int[] columnsLayouts = {R.id.item_title};
  ca = new SimpleCursorAdapter(this.getBaseContext(), R.layout.items_layout, cursor,columns , columnsLayouts);
  lv = getListView();
  lv.setAdapter(ca);
  </code></pre>
  
  <p>Now, if I select any item in the ListView, I want to have a reference to that item id.
  <strong>I want the id to retrieve other information from the table the item belong to. And retrieve it in other activity MsgView</strong></p>
  
  <p>I tried this:</p>
  
  <ul>
  <li><p>have a reference to the id passed when an item clicked</p></li>
  <li><p>pass that value with the intent, so that the other activity will retrieve the needed data using this passed value.</p>
  
  <pre><code>lv.setOnItemClickListener(new OnItemClickListener() {
      public void onItemClick(AdapterView&lt;?&gt; parent, View view,
          int position, long id) {
          Intent i = new Intent(view.getContext(), MsgView.class);
              i.putExtra("id", (int) id); //
              startActivity(i);
      }
      });
  </code></pre></li>
  </ul>
  
  <p>However, this didn't work. It seems that the id I'm using is not the item's id !
  Any solution or ideas ?</p>