Skip to content

Instantly share code, notes, and snippets.

@csdear
Created March 5, 2014 22:23
Show Gist options
  • Select an option

  • Save csdear/92e9bc718cd16b59f0d9 to your computer and use it in GitHub Desktop.

Select an option

Save csdear/92e9bc718cd16b59f0d9 to your computer and use it in GitHub Desktop.
SelectionListener Public Listener
package course.labs.notificationslab;
public interface SelectionListener {
public void onItemSelected(int position);
}
//Supporting Fragment class1
//field
private SelectionListener mCallback;
//onAttach m()
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
// This makes sure that the container activity has implemented
// the callback interface. If not, it throws an exception
try {
mCallback = (SelectionListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement SelectionListener");
}
}
@Override
public void onListItemClick(ListView l, View view, int position, long id) {
// Send the event to the host activity
mCallback.onItemSelected(position);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment