Instantly share code, notes, and snippets.

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);
public void onAttach(Activity 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");
public void onListItemClick(ListView l, View v, int p, long i) {
// Send the event to the host activity

This comment has been minimized.

Copy link

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