Home > Mobile >  Android: initializing a list with a large number of items
Android: initializing a list with a large number of items

Time:03-10

I need to use a list with more than 31 thousand strings for a dropdown menu. Now, if I declare this List/Array in java, I get the error that says the code is too large to compile. On the other hand, if I put these values in string-array in strings.xml, I get the message Resource compilation failed when I try to build the application.

What else can be done to store this list?

I don't want to keep the data in server and fetch it using API because it will increase my server cost.

CodePudding user response:

You could put the data into a table in a local SQLite Database (no servers needed), and then retrieve only the visible part when needed. I suggest to use a RecyclerView to show the list of item: it needs a bit more time to be implemented, but works very well with big lists of data.

Assuming that the list is static, you can include a pre-filled Database in your assets folder and copy it into the /databases folder when your application first launches. No need to fill it by the app using big arrays.

  • Related