/** * Little performance update, if the list is equally in size (not the best method) do not update the list */ public async override void ViewWillAppear(bool animated) { base.ViewWillAppear(animated); var newGames = await GameCall.GetAllGames(); if (games == null) { setupDatasource(newGames); } else if (games.Count != newGames.Count) { setupDatasource(newGames); } games = newGames; }
protected async override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // get all the games games = new List <Game>(); games = await GameCall.GetAllGames(); ListView listViewGames = FindViewById <ListView>(Resource.Id.games); // Assign adapter to ListView listViewGames.Adapter = new GameAdapter(this, games); listViewGames.ItemClick += listView_ItemClick; //Get all the buttons Button gamesBtn = FindViewById <Button>(Resource.Id.button1); Button leaderboardBtn = FindViewById <Button>(Resource.Id.button2); Button profileBtn = FindViewById <Button>(Resource.Id.button3); Button newGameBtn = FindViewById <Button>(Resource.Id.newGameBtn); //Set clickhandler to button gamesBtn.SetBackgroundResource(Resource.Color.green); gamesBtn.Click += (object sender, EventArgs e) => { //Select the games tab //Set the colors leaderboardBtn.SetBackgroundResource(Resource.Color.white); gamesBtn.SetBackgroundResource(Resource.Color.green); profileBtn.SetBackgroundResource(Resource.Color.white); listViewGames.Visibility = ViewStates.Visible; }; //Set clickhandler to button leaderboardBtn.Click += (object sender, EventArgs e) => { //Select the leaderboard tab //Set the colors leaderboardBtn.SetBackgroundResource(Resource.Color.green); gamesBtn.SetBackgroundResource(Resource.Color.white); profileBtn.SetBackgroundResource(Resource.Color.white); listViewGames.Visibility = ViewStates.Invisible; }; //Set clickhandler to button profileBtn.Click += (object sender, EventArgs e) => { //Select the profile tab //Set the colors profileBtn.SetBackgroundResource(Resource.Color.green); gamesBtn.SetBackgroundResource(Resource.Color.white); leaderboardBtn.SetBackgroundResource(Resource.Color.white); listViewGames.Visibility = ViewStates.Invisible; }; //Set clickhandler to button newGameBtn.Click += (object sender, EventArgs e) => { //Open the new game activity var activity = new Intent(this, typeof(NewGameActivity)); StartActivity(activity); }; LayoutInflater li = LayoutInflater.From(this); View promptsView = li.Inflate(Resource.Layout.dialog, null); //Create a Dialog to create a new user AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); // set prompts.xml to alertdialog builder alertDialogBuilder.SetView(promptsView); alertDialogBuilder.SetTitle("Username"); //Get the view items for the dialog userInput = (EditText)promptsView.FindViewById(Resource.Id.dialogText); imageView = (ImageView)promptsView.FindViewById(Resource.Id.imageView); imageBtn = (Button)promptsView.FindViewById(Resource.Id.imageBtn); //Add clickhandler to open the gallery imageBtn.Click += delegate { Intent = new Intent(); Intent.SetType("image/*"); Intent.SetAction(Intent.ActionGetContent); StartActivityForResult(Intent.CreateChooser(Intent, "Select Picture"), 1000); }; // set dialog message alertDialogBuilder .SetCancelable(false) .SetPositiveButton("OK", HandleTouchUpInside); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.Create(); // show it alertDialog.Show(); }