I have a recordset of about 29,000 records. My Screen contains EditText Box for Search Criteria and Listview containing all 29,000 records.
By searching with the lis
I would assume that you have passed aCityStateTemp
to you Adapter
as ArrayList
while initializing the Adapter
Now after changing the contents of aCityStateTemp
, you just need to call adapter.notifyDataSetChanged()
. you don't need to set the aCityStateTemp
to adapter as new ArrayList
.
You can use HashSet or LinkedHashSet(keeps insertion order) for fast searching. With contains() method of that classes.
I would insist to use Lambdaj Library which is mostly used in such cases where you want to restrict loops for sorting and filtering Collections.
Here is a small example for using lambdaj for filtering ArrayList
.
ArrayList<String> sortedArrayList = select(arrList, having(on(String.class),
Matchers.containsString("a");
This will return a complete filtered ArrayList
with which you want to populate your ListView
.
You can also filter
Custom Classes - Java: What is the best way to filter a Collection?
UPDATE:
Above solution was case-sensitive
so to work around you can add Multiple Matchers.
Like this you can add Multiple Matchers
,
ArrayList<String> sortedArrayList = select(arrList, having(on(String.class),
(Matchers.anyOf(Matchers.containsString("a"),Matchers.containsString("A")))));
UPDATE:
Even better way is to use filter(Matcher<?> matcher, T...array)
Here is how you can do that,
ArrayList<String> sortedArrayList = filter(Matchers.anyOf(
Matchers.containsString("a"),Matchers.containsString("A")), arrList);
Also, if you are interested in using some of the methods/features of lambdaj
, you can extract the source and get it working. I am adding the same for filter()
You can just download hamcrest-all-1.0.jar(63 kb) and add below code to get the filter()
working
public static <T> List<T> filter(Matcher<?> matcher, Iterable<T> iterable) {
if (iterable == null)
return new LinkedList<T>();
else{
List<T> collected = new LinkedList<T>();
Iterator<T> iterator = iterable.iterator();
if (iterator == null)
return collected;
while (iterator.hasNext()) {
T item = iterator.next();
if (matcher.matches(item))
collected.add(item);
}
return collected;
}
}
So, you can just sort out the least from lambdaj
source and integrate in your source.
You can store all data in a sqlite database and retrieve the searched item using like query.