Ollie C
Ollie C

Reputation: 28509

How to add more items at the bottom of an Android Array-backed ListView, and keep position?

I have a ListView with an ArrayAdapter providing the data. I'm adding paging, so when you scroll to the bottom it loads more rows.

But as I'm using an array I'm finding a problem. I can't extend the array as the size is obviously fixed, and if I create a new one, the ListView either ignores the new items (notifyDataSetChanged), or (if I refresh the list with the new array) it jumps to the top.

What's the usual way to do this? Use a different collection type? Use a large array with capacity for the maximum number of rows? Or is there a way to notify an adapter the dataset has changed and it actually works (notifyDataSetChanged() is not working in my scenario, probably because the array hasn't just changed, it's a completely different one, so the notify is probably working with the old one). Or should I set the adapter up with the new larger array, and jump it to the right position?

Upvotes: 2

Views: 607

Answers (1)

Kevin Coppock
Kevin Coppock

Reputation: 134664

You say ArrayList in the title, but you're talking about just an Array. Try using an ArrayList, you can add as many items as you need to with the ArrayList.add() method. Am I misunderstanding you, maybe?

Upvotes: 1

Related Questions