Instantly share code, notes, and snippets.

Embed
What would you like to do?
Good Old Way: Fragment
public class HeadlinesFragment extends ListFragment {
HeadlineListener mCallback;
// Container Activity must implement this interface
public interface HeadlineListener {
public void onArticleSelected(int position);
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
// Makes sure that the container activity has implemented
// the callback interface. If not, it throws an exception
try {
mCallback = (HeadlineListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement HeadlineListener");
}
}
@Override
public void onListItemClick(ListView l, View v, int p, long i) {
// Send the event to the host activity
mCallback.onArticleSelected(p);
}
}
@saguinav

This comment has been minimized.

Show comment
Hide comment
@saguinav

saguinav Sep 28, 2017

public class HeadlinesFragment extends ListFragment { There is a typo --> `HeadlineFragment

HeadlineListener mCallback; Hungarian notation?

saguinav commented Sep 28, 2017

public class HeadlinesFragment extends ListFragment { There is a typo --> `HeadlineFragment

HeadlineListener mCallback; Hungarian notation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment