I understand that one of the constructors for the SimpleCursorAdapter has been deprecated. The following constructor is the correct one to use:
SimpleCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags)
Can someone explain to me what that final parameter is and what I should place in there?
I have a method which uses a SimpleCursorAdapter and fills a custom layout file with data:
public void populateListView(){
Cursor cursor = myDB.getAllRows();
String[] fromFieldNames = new String[] {DBAdapter.KEY_NAME,DBAdapter.KEY_NUMBER,DBAdapter.KEY_EMAIL};
int[] toViewIDs = new int[] {R.id.customRowContactName,R.id.customRowContactNumber,R.id.customRowRowEmail};
SimpleCursorAdapter cursorAdapter;
cursorAdapter = new SimpleCursorAdapter(getActivity(),R.layout.contacts_custom_row,cursor,fromFieldNames,toViewIDs,WHAT DO I PLACE HERE);
myList = (ListView)view.findViewById(R.id.listViewFragment);
myList.setAdapter(cursorAdapter);
}
I placed a 1 in there for now just to get rid of the syntax error but am not sure how it affects my program.
According to docs:
int: Flags used to determine the behavior of the adapter
Thoose flags are used to determine how the CursorAdapter should monitor content changes (data was added or removed in the database)
It seems that you can choose one of flags below. However, one of them is deprecated and you should avoid them.
If dont want to monitor your content for changes, send 0.
If you want to track any change, use 2 (youay need to search more how to use it)
Value 0
According to this and this, you can send 0 and you cursor will not observe your content for changes.
Value 1
public static final int CursorAdapter.FLAG_AUTO_REQUERY Constant Value: 1 (0x00000001)
Added in API level 11 This constant was deprecated in API level 11. This option is discouraged, as it results in Cursor queries being performed on the application's UI thread and thus can cause poor responsiveness or even Application Not Responding errors. As an alternative, use LoaderManager with a CursorLoader.
If set the adapter will call requery() on the cursor whenever a content change notification is delivered. Implies FLAG_REGISTER_CONTENT_OBSERVER.
Value 2
public static final int CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER Constant Value: 2 (0x00000002)
Added in API level 11 If set the adapter will register a content observer on the cursor and will call onContentChanged() when a notification comes in. Be careful when using this flag: you will need to unset the current Cursor from the adapter to avoid leaks due to its registered observers. This flag is not needed when using a CursorAdapter with a CursorLoader.