Created
May 23, 2018 17:35
-
-
Save antonioxtasis/999467d5908e9bd6b7227448d4a9272e to your computer and use it in GitHub Desktop.
Android - DialogFragment response to Activity
This file contains 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
public class MyActivity implements MyDialogFragment.Listener { | |
// ... | |
@Override | |
public void onMyEvent() { | |
// do something here | |
} | |
} | |
public class MyDialogFragment extends DialogFragment { | |
private Listener mCallback; | |
public interface Listener { | |
void onMyEvent(); | |
} | |
@SuppressLint("RestrictedApi") | |
@Override | |
public void setupDialog(final Dialog dialog, int style) { | |
super.setupDialog(dialog, style); | |
View contentView = View.inflate(getContext(), R.layout.dialog_fragment_custom, null); | |
dialog.setContentView(contentView); | |
mCallback = (Listener) getActivity(); | |
Button myBtn = (Button) dialog.findViewById(R.id.btn_custom); | |
myBtn.setOnClickListener(v -> { | |
mCallback.onDeletedEmoji(); | |
dismiss(); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment