aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBananeweizen <bananeweizen@gmx.de>2014-01-15 07:56:37 +0100
committerBananeweizen <bananeweizen@gmx.de>2014-01-15 07:56:37 +0100
commite83842077c5f5e3eb7005f1e9792f8b31ff63d94 (patch)
treecc69cf8a51d18515931ef27fce6eb8f254af04b5
parent9315e8fa15fba2b4ad640544aeb88fb32666db9d (diff)
downloadcgeo-e83842077c5f5e3eb7005f1e9792f8b31ff63d94.zip
cgeo-e83842077c5f5e3eb7005f1e9792f8b31ff63d94.tar.gz
cgeo-e83842077c5f5e3eb7005f1e9792f8b31ff63d94.tar.bz2
IllegalStateException in search suggestions
IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. Occurred only seldom. The filter already switches between background and UI thread, but the pointer to the result list was previously already updated in the background thread.
-rw-r--r--main/src/cgeo/geocaching/search/AutoCompleteAdapter.java20
1 files changed, 11 insertions, 9 deletions
diff --git a/main/src/cgeo/geocaching/search/AutoCompleteAdapter.java b/main/src/cgeo/geocaching/search/AutoCompleteAdapter.java
index c314bbe..123469c 100644
--- a/main/src/cgeo/geocaching/search/AutoCompleteAdapter.java
+++ b/main/src/cgeo/geocaching/search/AutoCompleteAdapter.java
@@ -15,7 +15,7 @@ import android.widget.Filter;
*/
public class AutoCompleteAdapter extends ArrayAdapter<String> {
- private String[] results;
+ private String[] suggestions;
private final Func1<String, String[]> suggestionFunction;
public AutoCompleteAdapter(Context context, int textViewResourceId, final Func1<String, String[]> suggestionFunction) {
@@ -25,12 +25,12 @@ public class AutoCompleteAdapter extends ArrayAdapter<String> {
@Override
public int getCount() {
- return results.length;
+ return suggestions.length;
}
@Override
public String getItem(int index) {
- return results[index];
+ return suggestions[index];
}
@Override
@@ -45,18 +45,20 @@ public class AutoCompleteAdapter extends ArrayAdapter<String> {
}
String trimmed = StringUtils.trim(constraint.toString());
if (StringUtils.length(trimmed) >= 2) {
- results = suggestionFunction.call(trimmed);
+ String[] newResults = suggestionFunction.call(trimmed);
- // Assign the data to the FilterResults
- filterResults.values = results;
- filterResults.count = results.length;
+ // Assign the data to the FilterResults, but do not yet store in the global member.
+ // Otherwise we might invalidate the adapter and cause an IllegalStateException.
+ filterResults.values = newResults;
+ filterResults.count = newResults.length;
}
return filterResults;
}
@Override
- protected void publishResults(CharSequence constraint, FilterResults results) {
- if (results != null && results.count > 0) {
+ protected void publishResults(CharSequence constraint, FilterResults filterResults) {
+ if (filterResults != null && filterResults.count > 0) {
+ suggestions = (String[]) filterResults.values;
notifyDataSetChanged();
}
else {