Home > Mobile >  How to add large amounts of data to Android listview
How to add large amounts of data to Android listview

Time:09-17

I want to add a large amounts of data around 500 list items. How do I do this without spending much time, typing each item in the adapter?

CodePudding user response:

First of all, as people have mentioned, it is advisable to use RecyclerView instead of ListView. The RecyclerView is made for holding a lot of items while the ListView would probably have issues and take a lot of resources trying to display 500 items.

Now, if you want to add a lot of data unfortunately you most likely will not be able to avoid a bit of menial work in just typing it out. If you just want dummy data you can create a loop that will create an item in your adapter and fill it with random numbers and/or String options from a predefined array.

However, I suspect this may not be your goal. If you have predefined data that needs to be in your list and this data is already stored elsewhere, be it in a JSON file or a database, you could consider creating a small piece of code or script to adapt it from one location to your list.

If none of this is the case you really will just have to manually put it in.

CodePudding user response:

As far as I know you can pass Arrays or lists in the ListView. So the real problem is to add the items in that Array or the List that you're passing to your ListView.

But as you have not mentioned the type of data that you want to pass.

Using loops is the most general solution in this case.

  • Related