title: How to get row id of database on clicking a list item in a custom ListView?
body: <p>I have defined a custom itemAdapter class that populates my <code>ListView</code> from a database. My database has about 11 columns out of which my list displays only name, address and other relevant details. When i click on the list item, my app calls an intent and starts another activity which shows all the details for the database row which was clicked from the list. But i am unable to get the <code>rowid</code> to do this. My app always gives a runtime error and asks to <code>Force Close</code>. Below is a part of my <code>onCreate()</code>  method:</p>
  
  <pre><code>    ListView lv;
      //other parts of code
  
      lv.setOnItemClickListener(new OnItemClickListener() {
          public void onItemClick(AdapterView&lt;?&gt; parent, View v, int position,
          long id) {
              listIntent = new Intent(garageFinder.this,list_detail.class);
              Cursor c= (Cursor)itemsAdapter.getItem(position);
              listIntent.putExtra("g",c.getInt(c.getColumnIndex("_id")));
              startActivity(listIntent);
          }
          });
  </code></pre>
  
  <p>For retrieving the extras from intent i am using this:</p>
  
  <pre><code>    Bundle bundle= getIntent().getExtras();
      int id = bundle.getInt("g");
  </code></pre>
  
  <p>Well, i closed my cursor as suggested but some problems still persist. Below is the error log:</p>
  
  <pre><code>02-18 17:25:43.718: ERROR/AndroidRuntime(526): FATAL EXCEPTION: main
  02-18 17:25:43.718: ERROR/AndroidRuntime(526): java.lang.ClassCastException: java.lang.Integer
  02-18 17:25:43.718: ERROR/AndroidRuntime(526):     at car_app.garage.garageFinder$1.onItemClick(garageFinder.java:82)
  02-18 17:25:43.718: ERROR/AndroidRuntime(526):     at android.widget.AdapterView.performItemClick(AdapterView.java:284)
  02-18 17:25:43.718: ERROR/AndroidRuntime(526):     at android.widget.ListView.performItemClick(ListView.java:3382)
  02-18 17:25:43.718: ERROR/AndroidRuntime(526):     at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696)
  02-18 17:25:43.718: ERROR/AndroidRuntime(526):     at android.os.Handler.handleCallback(Handler.java:587)
  02-18 17:25:43.718: ERROR/AndroidRuntime(526):     at android.os.Handler.dispatchMessage(Handler.java:92)
  02-18 17:25:43.718: ERROR/AndroidRuntime(526):     at android.os.Looper.loop(Looper.java:123)
  02-18 17:25:43.718: ERROR/AndroidRuntime(526):     at android.app.ActivityThread.main(ActivityThread.java:4627)
  02-18 17:25:43.718: ERROR/AndroidRuntime(526):     at java.lang.reflect.Method.invokeNative(Native Method)
  02-18 17:25:43.718: ERROR/AndroidRuntime(526):     at java.lang.reflect.Method.invoke(Method.java:521)
  02-18 17:25:43.718: ERROR/AndroidRuntime(526):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
  02-18 17:25:43.718: ERROR/AndroidRuntime(526):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
  02-18 17:25:43.718: ERROR/AndroidRuntime(526):     at dalvik.system.NativeStart.main(Native Method)
  </code></pre>