Since working with Android I'm curious about how I can let Android do everything in respect to orientation change (layout vs. layout-land).
Currently I have to feed the correct number of db columns and views to the cursor adapter. Is this the correct way or do I miss something? How do you guys do that?
Please have a look at the two SimpleCursorAdapter where I feed the same layout name of both existing layouts (there's on in layout and one in layout-land). The only difference is the additional db column "type" and the additional view "R.id.activities_row_text3".
Is this the correct way?
Cursor cursor;
SimpleCursorAdapter simpleCursorAdapter = null;
if ((cursor = db.fetchActivities(connection)) != null) {
startManagingCursor(cursor);
int orientation = getResources().getConfiguration().orientation;
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
simpleCursorAdapter = new SimpleCursorAdapter(
this,
R.layout.activities_row,
cursor,
new String[] {
"name",
"time" },
new int[] {
R.id.activities_row_text1,
R.id.activities_row_text2 });
} else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
simpleCursorAdapter = new SimpleCursorAdapter(
this,
R.layout.activities_row,
cursor,
new String[] {
"name",
"time",
"type" },
new int[] {
R.id.activities_row_text1,
R.id.activities_row_text2,
R.id.activities_row_text3 });
}
if (simpleCursorAdapter != null) {
setListAdapter(simpleCursorAdapter);
}
}
Many thanks in advance. HjW