1
In my activity I have it:
mBtnSignUp.Click += (object sender, EventArgs e) =>
{
//Pull up dialog
FragmentTransaction transaction = FragmentManager.BeginTransaction();
dialog_SignUp signUpDialog = new dialog_SignUp();
signUpDialog.Show(transaction, "dialog fragment");
signUpDialog.mOnSignUpComplete += signUpDialog_mOnSignUpComplete;
};
void signUpDialog_mOnSignUpComplete (object sender, OnSignUpEventArgs e)
{
Thread thread = new Thread (ActLikeARequest);
thread.Start ();
}
private void ActLikeARequest()
{
Thread.Sleep (3000);
}
And in the Dialog
have:
public class OnSignUpEventArgs : EventArgs
{
private string mFirstName;
private string mEmail;
private string mPassword;
public string FirstName
{
get{ return mFirstName; }
set{ mFirstName=value;}
}
public string Email
{
get{ return mEmail; }
set{ mEmail=value;}
}
public string Password
{
get{ return mPassword; }
set{ mPassword=value;}
}
public OnSignUpEventArgs (string firstName, string email, string password) : base()
{
FirstName = firstName;
Email = email;
Password = password;
}
}
class dialog_SignUp:DialogFragment
{
private Button mBtnSignUp;
private EditText mFirstName;
private EditText mEmail;
private EditText mPassword;
public event EventHandler<OnSignUpEventArgs> mOnSignUpComplete;
public override View OnCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
base.OnCreateView (inflater, container, savedInstanceState);
var view = inflater.Inflate (Resource.Layout.dialog_sign_up, container, false);
mBtnSignUp = view.FindViewById<Button> (Resource.Id.btnDialogEmail);
mFirstName = view.FindViewById<EditText> (Resource.Id.txtFirstName);
mEmail = view.FindViewById<EditText> (Resource.Id.txtEmail);
mPassword = view.FindViewById<EditText> (Resource.Id.txtPassword);
mBtnSignUp.Click += mBtnSignUp_Click;
return view;
}
void mBtnSignUp_Click (object sender, EventArgs e)
{
//User has clicked the sign up button
mOnSignUpComplete.Invoke (this, new OnSignUpEventArgs(mFirstName.Text, mEmail.Text, mPassword.Text));
this.Dismiss ();
}
public override void OnActivityCreated (Bundle savedInstanceState)
{
Dialog.Window.RequestFeature (WindowFeatures.NoTitle); //Sets the title bar to invisible
base.OnActivityCreated (savedInstanceState);
Dialog.Window.Attributes.WindowAnimations = Resource.Style.dialog_animation; //Set the animation
}
}
The question is, how do I pass data from my activity (strings) to mine Dialog
, so that when this is called, the TextViews (mFirstName, mEmail, mPassword)
stay with the Text = *strings passadas*
?
I think within your very class
dialog_SignUp
you can create a constructor of it that takes 3 arguments, which inOnCreateView
you will use to fill in these fields. You have already made this attempt?– Paulo Rodrigues
@Cesarmiguel now that said, tried and resulted Thank you! Post as a response to gain reputation. Hug
– Rui Quaresma
@Ruiquaresma, I didn’t answer :P
– CesarMiguel
@Cesarmiguel answered the comment ;)
– Rui Quaresma