How To Display, On Mainactivity, The Number Inserted On A Custom Alertdialogfragment With Edittext?
I'm using a custom alertdialog with an editText to insert a number, the alertdialog is working, but nothing happens when I click positive button, it should display the value insert
Solution 1:
You are not setting listener TestAlertDialogListener
in your Activity. Just make below changes and you will get it working.
Create a constructor in your TestAlertDialogFragment
which will set the listener for us. I am not pasting the whole code of the dialog, only essential fragments. The onCreateDialog
method will be as it was.
publicclassTestAlertDialogFragmentextendsDialogFragment {
// Use this instance of the interface to deliver action events
TestAlertDialogListener mListener;
publicTestAlertDialogFragment(TestAlertDialogListener mListener)
{
this.mListener=mListener;
}
publicinterfaceTestAlertDialogListener {
publicvoidonDialogPositiveClick(DialogFragment dialog, int i, String string);
publicvoidonDialogNegativeClick(DialogFragment dialog);
}
Change your activity code like this:
publicvoidshowTestAlertDialog(View v) {
// Create an instance of the dialog fragment and show itDialogFragmentd=newTestAlertDialogFragment(MainActivity.this);
d.show(getSupportFragmentManager(), "testAlertDialog");
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}
Post a Comment for "How To Display, On Mainactivity, The Number Inserted On A Custom Alertdialogfragment With Edittext?"