Mojo Risin
Mojo Risin

Reputation: 8142

listview adapter implementation

With the application i am working on i came with the following problem. I have a listview that should display data from a data base table. There are two scenarios that could happen:

So the problem is how to accomplish this behavior using ListView and ListAdapter.

So far i have solution for each scenario but no for the two together.

So any ideas how to implement this using one adapter, or just should i use ArrayAdapter and CursorAdapter depending on the case ?

Upvotes: 1

Views: 1135

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006549

Scenario one - the database table is filling dynamically and the listview also should dynamically display table's information e.g to grow depending on table size.

Try:

Scenario 1a: Whoever is getting the data not only puts it in the database, but tells the activity "here's some new data to display".

Databases are great data stores but are lousy pipes. Your "Scenario one" tries to use the database as a pipe -- instead, pipe around it.

Now, if the case is that you have both in-the-database data and new data coming in, you'll need to stitch those datasets together. You can use my MergeAdapter for it: give it two ListAdapters, one representing your existing data (perhaps a CursorAdapter) and one representing the new data (perhaps an ArrayAdapter). It will render them as a combined entity.

Upvotes: 1

Related Questions