The CursorAdapter
is much more complex to set up than the ArrayAdapter
. For one thing, we offer more options with the CursorAdapter
than we did with the ArrayAdapter
. Our CursorAdapter
can be made to display either one or two line list items, based on whether there are one or two columns specified. While the ArrayAdapter
includes some default filtering logic, we need to provide a little more support for the CursorAdapter
.
To start with, we allow for two different column naming conventions to be used, along with some defaults. Declare a utility method to find the expected column names from the
Intent
:private String getColumnName( final Intent intent, String primary, String secondary, String def) {
First, try and use the
primary
attribute name to get a column name:String col = intent.getStringExtra(primary);
If the column name is
null
, try thesecondary
attribute name:if(col == null) { col = intent.getStringExtra...