I would like to have an autocomplete feature for my user when they enter text in the text box. This is easily achievable with AutoCompleteTextView in android. Initially, I build my string array in /res/values/strings.xml as
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="autocomplete_list">
<item>text 1</item>
<item>text 2</item>
<item>... (many more) ...</item>
<item>text 1499</item>
<item>text 1500</item>
</string-array>
</resources>
In my java code, i have
// load autocomplete list
String[] textList= getResources().getStringArray(R.array.autocomplete_list);
myAutoCompleteTextView.setAdapter(new ArrayAdapter<String>(this, R.layout.autocomplete_list, textList));
This worked fine when I only have a few things on my string. However, if my list is really long, say over 1000 items, i get run time error. The application will close on its own without any warning (no app forced closed error). It just disappears. Nothing in the logcat.
So am i exceeding maximum element indexable in string array in Java? is that what's causing the problem? If so, anyone knows what the max is? It does not seem like a memory problem since i don't get the OutOfMemory error.
Edit:
So apparently this is widely known problem, seems like a limit on the getResource().getStringArray() limitation
Should I be using something other than getResource().getStringArray() to populate a large array?
Going to try his solution first to see how well it works, but if you know a better way to do it, please feel free to share. Thanks!