Created
May 2, 2014 07:49
-
-
Save emmgfx/0f018b5acfa3fd72b3f6 to your computer and use it in GitHub Desktop.
Android JSONArray remove before API 19
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example of use: remove(i, savedProfiles); | |
public static JSONArray remove(final int idx, final JSONArray from) { | |
final List<JSONObject> objs = asList(from); | |
objs.remove(idx); | |
final JSONArray ja = new JSONArray(); | |
for (final JSONObject obj : objs) { | |
ja.put(obj); | |
} | |
return ja; | |
} | |
public static List<JSONObject> asList(final JSONArray ja) { | |
final int len = ja.length(); | |
final ArrayList<JSONObject> result = new ArrayList<JSONObject>(len); | |
for (int i = 0; i < len; i++) { | |
final JSONObject obj = ja.optJSONObject(i); | |
if (obj != null) { | |
result.add(obj); | |
} | |
} | |
return result; | |
} |
in may code json array is not using this remove method instead is using the internal method
........what to do?
is this method reliable to run on UI thread?
or do I need to wrap this in an AsyncTask?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Excellent, thank you very much!