Created
March 5, 2014 22:23
-
-
Save csdear/92e9bc718cd16b59f0d9 to your computer and use it in GitHub Desktop.
SelectionListener Public Listener
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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