I'm want to send some data to an altert dialog, to know identify winner player in my game.
Here is the code in my MainActivity.java:
if (game.comprobarCuatro(Game.JUGADOR)) {
dibujarTablero();
resultadoTextView.setText(R.string.gana_humano);
new AlertDialogFragment().show(getFragmentManager(),"ALERT DIALOG");
return;
}
And here is my code in AlertDialogFragment.java, where I want to display a different Tittle, according to the received input.
public class AlertDialogFragment extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final MainActivity main = (MainActivity) getActivity();
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
getActivity());
alertDialogBuilder.setTitle(R.string.fin_del_juego);
alertDialogBuilder.setMessage(R.string.fin_message);
alertDialogBuilder.setPositiveButton("Si",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
main.game.restart();
main.dibujarTablero();
dialog.dismiss();
}
});
alertDialogBuilder.setNegativeButton("No",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
main.finish();
dialog.dismiss();
}
});
return alertDialogBuilder.create();
}
}
My question is, how do I send that information to the dialog to show in the title a different message each time? Is it possible to send information to an alert dialog?
Doing some research somebody suggested to use save it in the preferences and read it later, which I don't think is a good solution.
Thank you!