androidlistactivity

Android - Application with multiple ListActivity resulting in correct Id in onListItemClick


I'm writing an android app which has 2 ListActivity.

ListActivity 1 -> OnItemClick -> opens the details page correctly ListActivity 1 -> Menu Option -> Opens ListActivity 2 ListActivity 2 -> OnItemClick -> Should Open details of the list item of ListActivity 2

However the 'id' that I get in the onListItemClick of the second list activity is incorrect.

ListActivity 1 onListItemClick handler:

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);

Intent c = new Intent(this, ADisplay.class);
c.putExtra(ABDbAdapter.A_FIELD_ID, id);
startActivityForResult(c, ACTIVITY_DISPLAY);
}

ListActivity 2 onListItemClick handler:

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);

Intent c = new Intent(this, TDisplay.class);
c.putExtra(ABDbAdapter.T_FIELD_ID, id);
startActivityForResult(c, ACTIVITY_DISPLAY);
}

ListActivity 1 has data from table 1 with primary key "_id" ListActivity 2 has data from table 2 with primary key "_id". Could this be the issue?


Solution

  • The issue has been resolved. The second listactivity was created by fetching data from tables with join. Both tables had _id field & the select used was 'Select *' instead of 'Select '. This resulted in the id of the first table being returned though I was expecting the id from the second table.

    Corrected the join statement and the issue is resolved.

    Thanks BBdev & Barak for responding