GetView Vs. BindView in a custom CursorAdapter?

后端 未结 3 632
青春惊慌失措
青春惊慌失措 2020-11-28 03:04

So, I\'m watching this video http://www.youtube.com/watch?v=N6YdwzAvwOA and Romain Guy is showing how to make more efficient UI adapter code using the getView()

3条回答
  •  死守一世寂寞
    2020-11-28 03:24

    The CursorAdapter implementation is different from sub-classing regular adapters like BaseAdapter, you don't need to override getView(), getCount(), getItemId() because that information can be retrieved from the cursor itself.

    Given a Cursor, you only need to override two methods to create a CursorAdapter subclass:

    bindView() : Given a view, update it to display the data in the provided cursor.

    newView() : This gets called to consctruct a new view that goes into the the list.

    The CursorAdapter will take care of recycling views (unlike the getView() method on regular Adapter). It doesn't call the newView() each time it needs a new row. If it already has a View(not null), it will directly call the bindView(), this way, the created view is reused. By splitting the creation and population of each view into these two methods, the CursorAdapter achieves view reuse where as, in regular adapters, both these things are done in getView() method.

提交回复
热议问题