public async override void ViewDidLoad() { base.ViewDidLoad(); users = new List <iOSUser>(); //Get all the users (for better performance, convert to paginated lists) var userList = await UserCall.getUsers(); if (userList == null) { var alertController = UIAlertController.Create("Warning", "Could not connect to server, please try again.", UIAlertControllerStyle.Alert); alertController.AddAction(UIAlertAction.Create("Try Again", UIAlertActionStyle.Default, alert => ViewDidLoad())); alertController.AddAction(UIAlertAction.Create("No thanks", UIAlertActionStyle.Default, alert => System.Diagnostics.Debug.Write("No thanks was selected"))); this.PresentViewController(alertController, true, null); } else { // Get the image and reload the list when done foreach (var user in userList) { UIImage image = await IOSImageUtil.FromUrl(user.imageUrl); var iosUser = new iOSUser(image, user); users.Add(iosUser); System.Diagnostics.Debug.WriteLine("NR OF USERS IN LIST: " + users.Count); playersTableView.Source = new SelectPlayerDatasource(users, this); playersTableView.ReloadData(); } } }
protected override async void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.NewGame); // Get all the users from the server users = await UserCall.getUsers(); //Set click to imageView to set user ImageView newTeam1Player1Image = FindViewById <ImageView>(Resource.Id.newTeam1Player1Image); newTeam1Player1Image.SetImageResource(Resource.Mipmap.noImage); newTeam1Player1Image.Click += (object sender, EventArgs e) => { clicked = 1; createAlert(); }; //Set click to imageView to set user ImageView newTeam1Player2Image = FindViewById <ImageView>(Resource.Id.newTeam1Player2Image); newTeam1Player2Image.SetImageResource(Resource.Mipmap.noImage); newTeam1Player2Image.Click += (object sender, EventArgs e) => { clicked = 2; createAlert(); }; //Set click to imageView to set user ImageView newTeam2Player1Image = FindViewById <ImageView>(Resource.Id.newTeam2Player1Image); newTeam2Player1Image.SetImageResource(Resource.Mipmap.noImage); newTeam2Player1Image.Click += (object sender, EventArgs e) => { clicked = 3; createAlert(); }; //Set click to imageView to set user ImageView newTeam2Player2Image = FindViewById <ImageView>(Resource.Id.newTeam2Player2Image); newTeam2Player2Image.SetImageResource(Resource.Mipmap.noImage); newTeam2Player2Image.Click += (object sender, EventArgs e) => { clicked = 4; createAlert(); }; //Create a new game game = new Game(); game.team1 = new Team(); game.team2 = new Team(); Button createGame = FindViewById <Button>(Resource.Id.createGameBtn); createGame.Click += async(object sender, EventArgs e) => { if (game.team1.player1 != null && game.team2.player1 != null) { //Create a new game await GameCall.createGame(game); //Open main activity var activity = new Intent(this, typeof(MainActivity)); StartActivity(activity); } }; }