Skip to content

Instantly share code, notes, and snippets.

@dmitriy-chernysh
Last active August 29, 2015 14:17
Show Gist options
  • Save dmitriy-chernysh/6d83d6af83e8afe2003b to your computer and use it in GitHub Desktop.
Save dmitriy-chernysh/6d83d6af83e8afe2003b to your computer and use it in GitHub Desktop.
[Android] Alert dialog
public class SampleDialog extends DialogFragment {
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
View view = getActivity().getLayoutInflater().inflate(R.layout..... , null);
return new AlertDialog.Builder(getActivity())
.setView(view)
.setTitle(R.string.....)
.setPositiveButton(android.R.string.ok, null)
.create();
}
}
import android.support.v4.app.FragmentManager;
...............
public class SomeClass extends Fragment{
private static final String DIALOG_TAG = "sometag";
.............
//call the alert dialog
FragmentManager fm = getActivity().getSupportFragmentManager();
SampleDialog dialog = new SampleDialog();
dialog.show(fm, DIALOG_TAG);
..............
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment