Reputation: 3725
I have about 700 items to display in the grid view.
On a Samsung Galaxy Tab 10.1 this is not a problem: it has enough memory. On a HTC Explorer the heap is overflown.
So I want to load data dynamically regarding current scroll position (N rows for screen + 5 rows as a tail). And I want to show a scrollbar which represents the position in total rows. But I don't want to draw items that I don't see.
In other words, I want to create something similar to UITableView
in iOS. How can I do this?
Upvotes: 0
Views: 1096
Reputation: 3470
Android Adapter
works in a similar way to iOS UITableViewDataSource
. You need to call
public void setAdapter (ListAdapter adapter)
on your GridView
and then that Adapter will get call backs like:
public int getCount ()
public View getView (int position, View convertView, ViewGroup parent)
It's important that you reuse convertView
the same way you dequeue a UITableViewCell
in
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
If you do all that correctly, it will never try to load all the views at once, but only the ones currently displayed and you shouldn't have memory problems any more.
Upvotes: 2
Reputation: 10352
You should use a ListView that is able to reuse View objects so that you don't have to instantiate so many objects.
Upvotes: 0