In activity A I am loading a list with all the values from my table and have set a setOnItemClickListener to start activity B and send an uri with the selected item's id[1] via send data
[1]
Uri currentTestUri = ContentUris.withAppendedId(TestEntry.CONTENT_URI, id);
In activity B I have my onCreateLoader with the projection:
String[] projection = {
TestEntry._ID,
TestEntry.COLUMN_TEST_ONE,
TestEntry.COLUMN_TEST_TWO}
...with the return statement
return new CursorLoader(this,
mCurrentTestUri, //Got this from Activity A
projection,
null,
null,
null);
And my onLoadFinished looks something like this:
if (cursor.moveToFirst()) {
int oneColumnIndex = cursor.getColumnIndex(TestEntry.COLUMN_TEST_ONE);
int twoColumnIndex = cursor.getColumnIndex(TestEntry.COLUMN_TEST_TWO);
String currentOne = cursor.getString(oneColumnIndex);
String currentTwo = cursor.getString(twoColumnIndex);
textViewOne.setText(currentOne);
textViewTwo.setText(currentTwo);
}
So far so good, now I wish to show values from the next row (right beneath it) but with a different projection (I only need the _ID and COLUMN_TEST_ONE) and have onLoadFinished display COLUMN_TEST_ONE's value in textViewThree.
[values from both rows should be shown at the same time, not one or another]
I can get the ID of the next row from activity A with [2] and send it as a string via putExtra but that's about all I have so far.
[2]
String nextItemId = String.valueOf(listView.getItemIdAtPosition(position + 1));
if((position+1) < lListView.getCount()) {
intent.putExtra("prevID", nextItemId);
}
..or I could create a valid URI path with the next row ID and send it as a string from Activity A and convert it to a URI in activity B if needed with:
ContentUris.withAppendedId(TestEntry.CONTENT_URI, nextItemId)
How should I change my activity B to load values from the next row and the current one onCreate?
The problem is with your query:
Here you are specifying, that you want to query only rows, that have specific
id. Any row, which has differentidwon't be returned in theCursor.Instead, query the table with appropriate selection arguments:
Then you can get the value of
secondIdrow following way: