Skip to content

Instantly share code, notes, and snippets.

@antonioxtasis
Created May 23, 2018 17:35
Show Gist options
  • Save antonioxtasis/999467d5908e9bd6b7227448d4a9272e to your computer and use it in GitHub Desktop.
Save antonioxtasis/999467d5908e9bd6b7227448d4a9272e to your computer and use it in GitHub Desktop.
Android - DialogFragment response to Activity
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