SmiffyKmc
SmiffyKmc

Reputation: 891

Show items in ListView filtered by Date

I have a ListView in my application. It holds information belonging to an object. The most important value in the Object is a date value. I need to make sort the ListView items by date like so...

12-12-2018
13-12-2018
14-12-2018
15-12-2018

I can't assume the dates will come like that from the Web Service and they could bring back later ones before the upcoming ones.

I sorted the objects first and passed them into the adapter but felt that might be cumbersome and thought maybe the ListView might do this for me. Is there a better way of doing this or is this the best way? Will the adapter always render the items over each iteration of the list of objects?

Thanks

Upvotes: 0

Views: 316

Answers (1)

Robbit
Robbit

Reputation: 4358

In this article:

ListView is an adapter view that does not know the details, such as type and contents, of the views it contains.

From Android design pattern, ListView uses Adapter Pattern to display its content. And there is a case talking about this.

Also, there is another sound, ListView is MVC.

Whether Adapter Pattern or MVC, ListView doesn't hold the data by itself, it needs a Model to manage the data, and display it by Adapter.


Is there a better way of doing this or is this the best way?

Sort the data firstly and pass it to Adapter is the best way. ListView can't do it, it is only responsible for displaying the View. And in this way, your ListView will become more easier to maintain and expand, that means if you want change something on your data, you don't need to change anything on your ListView, you just need focus on your Model which hold your data.

Upvotes: 1

Related Questions