title: Fetching data from database from ListView's onItemClickListener
body: <p><strong>SOLVED BELOW</strong></p>
  
  <p>See below for solution</p>
  
  <hr>
  
  <p>I have a <code>ListView</code> with a custom adapter which extends <code>CursorAdapter</code>. When the user clicks on an item in the <code>ListView</code> I want to open a new <code>Activity</code>(launched from the <code>openDigitalBusinessCardActivity</code> method), with the new <code>Activity</code> based upon the particular item in the <code>ListView</code> that was clicked. The new <code>Activity</code> needs the field <code>merchantID</code> from the database so I need to access this and then pass to the new <code>Activity</code> in my <code>Intent</code>.</p>
  
  <p>However, I cannot get working how to access the correct data in my database based upon the feedback of the <code>ListView</code> click listener.</p>
  
  <p><code>Eclipse</code> gives me <code>Bad request for field slot</code> errors. My code for my listener is below:</p>
  
  <pre><code>    list.setOnItemClickListener(new OnItemClickListener() {
          public void onItemClick(AdapterView&lt;?&gt; parent, View view,
              int position, long id) {
            // When clicked, show a toast with the TextView text
            Toast.makeText(getApplicationContext(), "Click registered!",
                Toast.LENGTH_SHORT).show();
  
            db = myDbHelper.getReadableDatabase();
  
            //Cursor cur = (Cursor) adapter.getCursor();            
            //cur.moveToPosition(position);
            Cursor cur = (Cursor) parent.getItemAtPosition(position);
            //Cursor cur = (Cursor)((MyCustomCursorAdapter) list.getAdapter().getItem(position));
            int merchantID = cur.getInt(cur.getColumnIndex("merchantID")); //Get the merchantID
  
            db.close();
  
           openDigitalBusinessCardActivity(merchantID);             
          }
        });
  </code></pre>
  
  <p>My database creation code is this:</p>
  
  <pre><code>private static final String DATABASE_CREATE = 
                  "create table " + TABLE_SCORECARD + "(" 
                  + COLUMN_MERCHANTID + " integer primary key, " 
                  + COLUMN_MERCHANTNAME + " text not null, "
                  + COLUMN_MERCHANTTAGLINE + " text not null, "
                  + COLUMN_CURRENTSCORE + " Integer, "
                  + COLUMN_FREEBIEPOINT + " Integer, "
                  + COLUMN_CAMPAIGNID + " Integer, "
                  + COLUMN_LISTPOSITION + " Integer);";
  </code></pre>
  
  <p><strong>---UPDATE---</strong></p>
  
  <p>I have added an <code>_id</code> column to my table and now it looks like my query by the <code>_id</code> from <code>onItemClick</code> is not returning anything as my test on <code>cur.moveToFirst()</code> returns <code>false</code>. So <code>onItemClic</code>k is not returning a valid table row number.</p>
  
  <pre><code>list = getListView();
  
     list.setOnItemClickListener(new OnItemClickListener() {
          public void onItemClick(AdapterView&lt;?&gt; parent, View view,
              int position, long id) {
            // When clicked, show a toast with the TextView text
            Toast.makeText(getApplicationContext(), "Click registered!",
                Toast.LENGTH_SHORT).show();
  
            db = myDbHelper.getReadableDatabase();
  
            //Cursor cur = (Cursor) adapter.getCursor();            
            //cur.moveToPosition((int) id);
            //Cursor cur = (Cursor) parent.getItemAtPosition((int) id);
            //Cursor cur = (Cursor)((MyCustomCursorAdapter) list.getAdapter().getItem(position));
            Cursor cur = db.rawQuery("select merchantID from scoreCard where _id = "+id,null);
            if(cur.moveToFirst()) {
                //int merchantID = cur.getInt(cur.getColumnIndex("merchantID")); //Get the merchantID
                Toast.makeText(getApplicationContext(), "cur.moveToFirst returned true",
                        Toast.LENGTH_SHORT).show();
            }           
  
            cur.close();
            db.close();
  
           // openDigitalBusinessCardActivity(merchantID);              
          }
        });
  </code></pre>