Create a new constructor and instance variable:
AdapterInterface buttonListener; public MyListAdapter (Context context, Cursor c, int flags, AdapterInterface buttonListener) { super(context,c,flags); this.buttonListener = buttonListener; }
When you create the adapter, the instance variable will be assigned the correct hold reference.
To call a fragment from a click:
public void onClick(View v) { buttonListener.buttonPressed(); }
When creating the Adapter you also need to transfer your fragment to the adapter. for example
MyListAdapter adapter = new MyListAdapter (getActivity(), myCursor, myFlags, this);
since this will refer to your fragment, which is now AdapterInterface .
Keep in mind that when orienting changes to the Fragment, it will most likely be recreated. If your adapter is not recreated, it could potentially refer to a non-existent object, causing errors.
A - C Mar 16 '13 at 1:03 2013-03-16 01:03
source share