Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class LoginDialogFrag : DialogFragment
- {
- public static LoginDialogFrag NewInstance(Bundle bundle)
- {
- LoginDialogFrag fragment = new LoginDialogFrag {Arguments = bundle};
- return fragment;
- }
- public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
- {
- View view = inflater.Inflate(Resource.Layout.LoginDialog, container, false);
- Button loginBtn = view.FindViewById<Button>(Resource.Id.BtnLogin);
- var username = view.FindViewById<EditText>(Resource.Id.usernameTxt);
- var password = view.FindViewById<EditText>(Resource.Id.passwordTxt);
- loginBtn.Click += delegate
- {
- if (string.IsNullOrWhiteSpace(username.Text) || string.IsNullOrWhiteSpace(password.Text))
- {
- ShowDialog("Please fill out all the fields!");
- return;
- }
- CheckLogin(username.Text, password.Text);
- };
- return view;
- }
- private async void CheckLogin(string user, string pass)
- {
- //Checks the user http etc. then shows the Activity
- StartActivity(new Intent(Activity, typeof(LoginActivity)));
- }
- private void ShowDialog(string msg)
- {
- FragmentTransaction ft = FragmentManager.BeginTransaction();
- Fragment prev = FragmentManager.FindFragmentByTag("dialog");
- if (prev != null)
- {
- ft.Remove(prev);
- }
- ft.AddToBackStack(null);
- Fragment1 newFragment = Fragment1.NewInstance(null, msg);
- newFragment.Show(ft, "dialog");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement