am 927c7fd1: Merge "Fix crash when SimpleCursorAdapter changes cursor from null" into jb-dev
* commit '927c7fd1fec8ff26fd4bf8cc64eb12dd634cb60b': Fix crash when SimpleCursorAdapter changes cursor from null
This commit is contained in:
@@ -78,7 +78,7 @@ public class SimpleCursorAdapter extends ResourceCursorAdapter {
|
|||||||
super(context, layout, c);
|
super(context, layout, c);
|
||||||
mTo = to;
|
mTo = to;
|
||||||
mOriginalFrom = from;
|
mOriginalFrom = from;
|
||||||
findColumns(from);
|
findColumns(c, from);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -104,7 +104,7 @@ public class SimpleCursorAdapter extends ResourceCursorAdapter {
|
|||||||
super(context, layout, c, flags);
|
super(context, layout, c, flags);
|
||||||
mTo = to;
|
mTo = to;
|
||||||
mOriginalFrom = from;
|
mOriginalFrom = from;
|
||||||
findColumns(from);
|
findColumns(c, from);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -316,20 +316,21 @@ public class SimpleCursorAdapter extends ResourceCursorAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a map from an array of strings to an array of column-id integers in mCursor.
|
* Create a map from an array of strings to an array of column-id integers in cursor c.
|
||||||
* If mCursor is null, the array will be discarded.
|
* If c is null, the array will be discarded.
|
||||||
*
|
*
|
||||||
|
* @param c the cursor to find the columns from
|
||||||
* @param from the Strings naming the columns of interest
|
* @param from the Strings naming the columns of interest
|
||||||
*/
|
*/
|
||||||
private void findColumns(String[] from) {
|
private void findColumns(Cursor c, String[] from) {
|
||||||
if (mCursor != null) {
|
if (c != null) {
|
||||||
int i;
|
int i;
|
||||||
int count = from.length;
|
int count = from.length;
|
||||||
if (mFrom == null || mFrom.length != count) {
|
if (mFrom == null || mFrom.length != count) {
|
||||||
mFrom = new int[count];
|
mFrom = new int[count];
|
||||||
}
|
}
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
mFrom[i] = mCursor.getColumnIndexOrThrow(from[i]);
|
mFrom[i] = c.getColumnIndexOrThrow(from[i]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mFrom = null;
|
mFrom = null;
|
||||||
@@ -341,13 +342,8 @@ public class SimpleCursorAdapter extends ResourceCursorAdapter {
|
|||||||
// super.swapCursor() will notify observers before we have
|
// super.swapCursor() will notify observers before we have
|
||||||
// a valid mapping, make sure we have a mapping before this
|
// a valid mapping, make sure we have a mapping before this
|
||||||
// happens
|
// happens
|
||||||
if (mFrom == null) {
|
findColumns(c, mOriginalFrom);
|
||||||
findColumns(mOriginalFrom);
|
return super.swapCursor(c);
|
||||||
}
|
|
||||||
Cursor res = super.swapCursor(c);
|
|
||||||
// rescan columns in case cursor layout is different
|
|
||||||
findColumns(mOriginalFrom);
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -367,11 +363,8 @@ public class SimpleCursorAdapter extends ResourceCursorAdapter {
|
|||||||
// super.changeCursor() will notify observers before we have
|
// super.changeCursor() will notify observers before we have
|
||||||
// a valid mapping, make sure we have a mapping before this
|
// a valid mapping, make sure we have a mapping before this
|
||||||
// happens
|
// happens
|
||||||
if (mFrom == null) {
|
findColumns(c, mOriginalFrom);
|
||||||
findColumns(mOriginalFrom);
|
|
||||||
}
|
|
||||||
super.changeCursor(c);
|
super.changeCursor(c);
|
||||||
findColumns(mOriginalFrom);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user