dimanche 1 mars 2015

Android onItemClick giving Incorrect id

I am trying to get the details for a clicked item in a ListView by querying the SQLite database. I am passing the long id value from onItemClick as the primary key. However, the long id does not match with the actual primary key in the Table. I found out the actual primary key by querying for the primary keys of all the rows in the Table.


I have the following questions: 1. Am I right in assuming that the long id parameter in onItemClick(AdapterView parent, View view, int position, long id) carries the primary key of the item in the database table?



  1. If not, how should I get the primary key?


I have appended my code below:



list.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {

public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

//Display Client Details
Intent displayclient = new Intent(view.getContext(), display_clientdetails.class);
Integer db_id = (int) id;

String TAG = "client_list";
Log.d(TAG,"Position is" +position +" ID is " +db_id);

displayclient.putExtra("client_id",db_id);
view.getContext().startActivity(displayclient);

}


});


Aucun commentaire:

Enregistrer un commentaire