mardi 30 décembre 2014

How can I get the row id of the a table in the sqlite database when an Item is clicked in the listview

My code goes here.............! when there is a row deleted from the list-view. The indexes of the rows of the listview is changed but the primary key id in the database is not changed. now when i click the item and pass the position of the clicked item of the listview to the new activity. And try to retrieve the record with that ID it does not return me something or incorrect data is returned. now my question is how can I detect the row id of the clicked item of listview in the database. Now what should be code inside the onItemclick method to retrieve the correct rows from the database.


Thanks in anticiaption......!



protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myDb = new DBHelper(this);
titles = myDb.getAllNames();
times = myDb.getAllTimes();

ArrayAdapter<String> ad = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, titles);
lv = (ListView) findViewById(R.id.listView1);
lv.setAdapter(ad);

lv.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3)
{

}
});



}

Aucun commentaire:

Enregistrer un commentaire