How can I dynamically add images to a GridView?

后端 未结 2 1286
无人及你
无人及你 2020-12-17 05:18

I have a GridView that is created based on an array of items. I need to add more images as the grid is scrolled to the bottom, but I\'m not sure how to do that.

相关标签:
2条回答
  • 2020-12-17 05:30

    You can get reference to the adapter backing the GridView by .getAdapter(). When the user scrolled down, get this adapter, add the new images (I think you should use an ArrayList instead of simple arrays so you can easily append more data in the ImageAdapter class), and call .notifyDatasetChanged() on the now modified adapter, so it'll load in the new data.

    0 讨论(0)
  • 2020-12-17 05:41

    You should be able to call getAdapter on the gridview. Or -- it might not be the best practice -- but you could make the Adapter static, which would let you have access from your Grid Activity. Then, you could add images to the adapters on the fly and reset your layout.

    Give it a try. It's what I would do. If you find a better way let me know!

    0 讨论(0)
提交回复
热议问题