Question

I get data from my server returned as an array of objects. Each object is itself an array of strings that describe the object.

For example let's use cars as the object. In this case, the array of strings are descriptors like 'year built', 'horsepower', 'automatic or manual', 'color', etc etc.

What I'd like to do is display only 1 car at a time for the user. The user can choose whether he likes or dislikes the car. Either way, a choice is final, and the next car will show up. Also, the user should not be able to go back to the previous car (not with a swipe or a clicking of aback button). In other words, he can never see his choice on the previous car again.

If I make a call to my server on every single 'like/dislike', this will be a very slow app. If I inflate a bunch of data into many views that are out of sight, it will also be a very slow app.

Most Array Adapter examples I see online illustrate how to show data bi-directionally. They are viewpagers or listviews that you can swipe left (or up) to view data that has been previously already viewed. This is not what I'm looking for.

Is there a proper way to implement what I'm trying to do? Any help will be appreciated as I'm just hoping to get some direction and can implement on my own. So far I'm thinking about possibly a viewpager that deletes items as you view them, but I have a feeling this will be really hard to manage the position of the views...

Was it helpful?

Solution

Use an array to hold the data you get from the server. You can request that the server send you 10 or 25 or 50 at a time.

Since you only want to show the user 1 at a time, and he can't scroll or swipe through the list, you only need a single set of views (enough to show all attributes of a single entry). You don't need an array adpater for this. Whenever you step from one entry to the next you just need to adjust the index into your array and then copy all the attributes of the new item into the individual views with setText() or setImageBitmap() or whatever.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top