Advertisement
Guest User

Untitled

a guest
Aug 14th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. public class LoginDialogFrag : DialogFragment
  2. {
  3.  
  4. public static LoginDialogFrag NewInstance(Bundle bundle)
  5. {
  6. LoginDialogFrag fragment = new LoginDialogFrag {Arguments = bundle};
  7. return fragment;
  8. }
  9.  
  10. public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
  11. {
  12. View view = inflater.Inflate(Resource.Layout.LoginDialog, container, false);
  13.  
  14. Button loginBtn = view.FindViewById<Button>(Resource.Id.BtnLogin);
  15. var username = view.FindViewById<EditText>(Resource.Id.usernameTxt);
  16. var password = view.FindViewById<EditText>(Resource.Id.passwordTxt);
  17.  
  18. loginBtn.Click += delegate
  19. {
  20. if (string.IsNullOrWhiteSpace(username.Text) || string.IsNullOrWhiteSpace(password.Text))
  21. {
  22. ShowDialog("Please fill out all the fields!");
  23. return;
  24. }
  25. CheckLogin(username.Text, password.Text);
  26. };
  27. return view;
  28. }
  29.  
  30. private async void CheckLogin(string user, string pass)
  31. {
  32. //Checks the user http etc. then shows the Activity
  33. StartActivity(new Intent(Activity, typeof(LoginActivity)));
  34. }
  35.  
  36.  
  37. private void ShowDialog(string msg)
  38. {
  39. FragmentTransaction ft = FragmentManager.BeginTransaction();
  40. Fragment prev = FragmentManager.FindFragmentByTag("dialog");
  41. if (prev != null)
  42. {
  43. ft.Remove(prev);
  44. }
  45.  
  46. ft.AddToBackStack(null);
  47. Fragment1 newFragment = Fragment1.NewInstance(null, msg);
  48. newFragment.Show(ft, "dialog");
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement