android CursorAdapter and BaseAdapter performance - android

I need to know which adapter is the best and fast performance between CursorAdapter and BaseAdapter? I always use BaseAdapter when I'm trying to display in ListView. But I know CursorAdapter is updated one and easy to manipulate but not sure which one is better. Or which adapter (or any adapter else) should I use to retrieve data from sqlite and display at ListView?

As seen in the CursorAdapter source, CursorAdapter is just a thin, convenience wrapper around BaseAdapter as you would expect and performs no expensive operations. The vast majority of the time spent displaying items will be in inflating, measuring, and laying out your views which needs to be done no matter what adapter you use. Therefore you should always use the one that provides the closest implementation to your needs. For SQLite database, that is almost exclusively CursorAdapters.

Related

ORMLite performance: ArrayAdapter vs CursorAdapter vs a custom adapter

I have relatively small H2 database. I am expecting no more than 100 entries and even that feel highly over the top.
I have a list view with some controls and use an ArrayAdapter with a call to QueryAll() to populate the data. It works perfectly as I can modify the data in the array in memory when a button is pressed and then write the result to DB without having to reload it. But the initial load is surprisingly slow
What I wonder is whether I should rather use a CursorAdapter, since it seems more fitting to the problem or write a custom adapter to make use of the DAO Iterator.
Will there be a performance improvement using Cursor or a custom adapter? In my mind it feels like a custom adapter should give the best performance.
CursorAdapter is more appropriate when there is a database because it does not load all the records as ArrayAdapter. It loads only the visible records in the ListView is between 5 and 10.
So I think if you use a CursorAdapter you will not have loading problems.
Regards
Its better to use a custom adapter with
Content provider.

How does CursorAdapter recycle Views in ListView?

I know that BaseAdapter has a mechanism in order to recycle Views in a ListView for efficiency. But how does it work in CursorAdapter exactly? Is it the same thing? I haven't really found any documentation on this. The closest there was is with the World of ListView's google IO video, but that doesn't take into account CursorAdapter. Any advice on the matter would be much appreciated!
The getView() method is responsible for recycling the row views(it's the same thing as for a non cursor based adapter, just that it delegates the row construction and data binding to two different methods) and for moving the Cursor to the correct position.

What is the difference between base-, array- and cursor-adapter

Should I use array adapter or base adapter or cursor adapter?
What do you use most? I found some code that uses base adapter for fragments. Can I use array adapter or cursoradapter for listfragments?
I know how to use listview in a simple way like using the android.r.simple. I want to know what I should use in creating a listview that uses listfragment and populating it with data that came from SQLite.
What is the easiest adapter to use to achieve this?
There are difference between the different adapter class. You should decide to use one depending on your model data.
ArrayAdapter is better if you have an ArrayList of objects.
CursorAdapter is better if you have a database query and a Cursor
BaseAdapter is the most customizable, so you can use it for anything (you have to customize it a little bit more than others)
I normally end up extending BaseAdapter. It's simple enough, and ArrayAdapter isn't flexible enough to handle the case where items have multiple values that need to go into different fields in your list item.

Best ListViewAdapter for multiple row types?

I need to implement a ListAdapter for multiple row types. So pick a layout per row based on the content of that row. I would like to hear some opinions on the merits of the different types of ListAdapters for accomplishing this. I don't expect to have thousands of rows or even a hundred, but I may potentially have quite a few different layouts and need a flexible easy to understand implementation.
So I am considering
BaseAdapter
ArrayAdapter
CursorAdapter
SimpleCursorAdapter
What are some of the advantages/disadvantages of these adapters. Would a cursor based adapter be better?
I want a it to be flexible, easy to change and work reliably.
The adapters are there to adapt a data source to the view, so it really comes down to your data source.
If its a database data source and you have largely straight-froward mappings of columns to text and image views, start with SimpleCursorAdapter.
If its a database data source but a lot of custom mappings or if you end up overriding a lot of SimpleCursorAdapter's functionality anyway, take a look at CursorAdapter.
If the data source is something that can viewed as an array, the look at ArrayAdapter.
If its a custom data source or if there's a alot of custom logic for binding the data to the views that doesn't fit the other adapters, derive your own adapter from BaseAdapter.

BaseAdapter or ArrayAdaptor - Android

I am going to make a grid of images and I am trying to figure out whether to use an array adaptor or a baseadaptor. While the GridView example, stores the data in an array, it uses a BaseAdapter rather than a ArrayAdaptor. I am curious why this is. One thing I noticed about an ArrayAdapter, is that its constructor takes a textViewResourceId for some unknown reason - although the documentation say the getView can be used to make it work with other kinds of views as well. So, if I want a fixed grid of images for a menu, which class would you recommend choosing?
You typically choose your adapter class based on what the model data is. If you have an ArrayList of objects, use ArrayAdapter. If you have a Cursor from a database query, use a CursorAdapter. BaseAdapter can be used for anything, but it requires more coding, since it has no innate knowledge of how to iterate over the data.

Categories

Resources