Search code examples
androidsimplecursoradapter

What happens to String[] from and int [] to when I override newView/bindView in SimpleCursorAdapter


Before I was extending SimpleCursorAdapter and overriding newView/getView I would specify which TextView's to populate with the to and from parameters in the constructor.

Now when I did override, the to/from parameters seem to be useless. If I don't pass a column name to "from" I can still access the column and at the same time I can't construct the adapter by passing null to both to/from (so I just pass one column not to get NullPointerException).

Should I be using to and from somehow in bindView? If so, how?


Solution

  • Now when I did override, the to/from parameters seem to be useless.

    A SimpleCursorAdapter is designed(as its name suggest) as a simple adapter to bind a limited range of views to a Cursor's data, mapping made through the two arrays(the columns names to views with the specified ids). If you override the SimpleCursorAdapter (especially the newView() and bindView() methods that do the binding)then those columns aren't really necessary because you'll take matters into your own hands.

    If I don't pass a column name to "from" I can still access the column and at the same time I can't construct the adapter by passing null to both to/from (so I just pass one column not to get NullPointerException).

    Although you'll probably do the mapping yourself(I don't know what methods you override and how) those columns are used in other part of the adapter's code so passing null for either one of those arrays should be avoided. Anyway the real problem is that the SimpleCursorAdapter is a simple class design for basic scenarios. If you find the need to override it then you better extend its super class CursorAdapter(which comes without those arrays) and do whatever you want.

    Should I be using to and from somehow in bindView? If so, how?

    As those arrays represent the columns from the Cursor and the ids of the views to which to bind the data then it would make sense to use them.