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.
Related
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.
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.
I've read multiple (a lot, actually) of questions here on StackOverflow and on other websites about which methods to override when making a CustomCursorAdapter, but I still don't understand.
Some say that getView() delegates directly to newView() and bindView(), so is therefore unnecessary in a CursorAdapter. However, it seems that using a getView() method is the only way to incorporate a ViewHolder.
My intention is to put a CheckBox in each row of my ListView, but I'm not sure how to deal with the view recycling.
Could somebody please clarify this for me? Thanks in advance.
Look at googleshelves project. They use a viewholder a newview and bindview. Personally I've always used getview.
Good day, this might be a silly question, am having a bit of dilemma as to how to create a listview with an imageview and two textview. I am using a cursor to query the MediaStore, but i don't know which adapter to use. I would have thought using Cursor Adapter, but keep seeing numerous examples of using an ArrayAdapter. so am asking, which adapter will best be used to create the listview? is there anything wrong in using CursorAdapter for this my problem or is CursorAdapter only used when you are getting data from a Sql database. Thank you.
Either should work for you, however the CursorAdapter is ... mainly for working with Cursors. As you Query the MediaStore you will notice that you are working with a Cursor, so this would be the best route.
ArrayAdapter will also work, but this is mainly when you are working with Lists or Arrays of items (List of MyObject or MyObject[]).
This question has an example of using a CursorAdapter with MediaStore. Here is a good read on Content Providers (which you might have already read).
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.