private void performSearch(String query) { ArrayList<Preference> nextEntries = null; JSONArray users = social.getSearchUsers(query, 20); if (users != null) { nextEntries = new ArrayList<>(); NicedPreferences.NiceListPreference lp; for (int inx = 0; inx < users.length(); inx++) { JSONObject user = Json.getObject(users, inx); String pfid = Json.getString(user, "pfid"); String name = Json.getString(user, "name"); String icon = Json.getString(user, "icon"); String type = Json.getString(user, "type"); if ((pfid == null) || (name == null) || (icon == null) || (type == null)) continue; if (name.isEmpty()) continue; lp = new NicedPreferences.NiceListPreference(Simple.getActContext()); String veryfied = Json.getBoolean(user, "very") ? " (" + "verified" + ")" : ""; lp.setTitle(name + veryfied); lp.setIcon(SimpleRequest.readDrawable(icon)); lp.setOrder(1000001 + inx); lp.setSlug(user); lp.setOnPreferenceChangeListener(searchResultClick); if (Simple.equals(type, "like")) { lp.setEntryValues(R.array.pref_social_newlikes_keys); lp.setEntries(R.array.pref_social_newlikes_vals); } else { lp.setEntryValues(R.array.pref_social_newfriends_keys); lp.setEntries(R.array.pref_social_newfriends_vals); } lp.setValue("inactive"); getPreferenceScreen().addPreference(lp); nextEntries.add(lp); } } if (lastEntries != null) { for (Preference nukeme : lastEntries) { getPreferenceScreen().removePreference(nukeme); } } lastEntries = nextEntries; }