spacecowboy/NotePad — Issue #23: Change fragment communication to interface
Author: spacecowboy
Created: 2012-01-20 10:13:34+00:00
State: open

Change from using ugly static references to interface like in the example at [android devs](http://developer.android.com/guide/topics/fundamentals/fragments.html)

```java
public static class FragmentA extends ListFragment {
OnArticleSelectedListener mListener;
...
// Container Activity must implement this interface
public interface OnArticleSelectedListener {
public void onArticleSelected(Uri articleUri);
}
...
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
mListener = (OnArticleSelectedListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString() + " must implement OnArticleSelectedListener");
}
}
...
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
// Append the clicked item's row ID with the content provider Uri
Uri noteUri = ContentUris.withAppendedId(ArticleColumns.CONTENT_URI, id);
// Send the event and Uri to the host activity
mListener.onArticleSelected(noteUri);
}
...
}
```