public override View GetView(int index, View convertView, ViewGroup parent) { View view = convertView; // Create a view if one doesn't already exist if (view == null) { view = _context.LayoutInflater.Inflate(this._listViewLayout, null); } // Get player and the two text fields that'll display player data Player player = _players[index]; TextView playerNameAndTeam = view.FindViewById <TextView>(Android.Resource.Id.Text1); TextView playerAdditionalDetails = view.FindViewById <TextView>(Android.Resource.Id.Text2); // Change formatting of TextView depending on if firstname is empty or not // An empty first name means the TextView doesn't need a space to separate first and last names string premierTeamName = premierTeamRepository.GetPremierTeamNameFromID(player.PremierTeamID); playerNameAndTeam.Text = NameTeamTextFormatting.FormatNameAndTeam(player.Firstname, player.Surname, premierTeamName); // Add position and player's price onto second line of text string playerPositionName = positionRepository.GetPositionNameByID(player.PositionID); playerAdditionalDetails.Text = playerPositionName + ", £" + player.Price + " million"; return(view); }
void InsertDataIntoUIComponents(FantasyTeam fantasyTeam, TextView teamDetailsTextView, TextView teamPriceTextView, ListView teamPlayersListView) { teamDetailsTextView.Text = NameTeamTextFormatting.FormatNameAndTeam(fantasyTeam.ManagerFirstname, fantasyTeam.ManagerSurname, fantasyTeam.FantasyTeamName); List <Player> fantasyTeamPlayers = playerRepository.GetAllPlayersOfAFantasyTeam(fantasyTeam.FantasyTeamID); teamPriceTextView.Text = "£" + CalculateTotalFantasyTeamCost(fantasyTeamPlayers).ToString() + " million"; teamPlayersListView.Adapter = new PlayerAdapter(this, fantasyTeamPlayers, Android.Resource.Layout.SimpleListItem2); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.PickTeams); // Getting UI elements from layout currentManagerTurnTextView = FindViewById <TextView>(Resource.Id.currentManagerTurn); remainingFantasyTeamBalance = FindViewById <TextView>(Resource.Id.remainingTeamBalance); selectablePlayersList = FindViewById <ListView>(Resource.Id.selectablePlayers); Button nextTurnButton = FindViewById <Button>(Resource.Id.nextTurnButton); // Disable next turn button until a player has been selected nextTurnButton.Enabled = false; // Create list view to show which players the user can select on their turn selectablePlayersList.ChoiceMode = ChoiceMode.Single; List <Player> selectablePlayers = new List <Player>(); PlayerAdapter selectablePlayersAdapter = new PlayerAdapter(this, selectablePlayers, Android.Resource.Layout.SimpleListItemActivated2); selectablePlayersList.Adapter = selectablePlayersAdapter; // Get a list of stages List <Stage> stages = Stages.GetStagesOfTeamSelection(); // Randomly select which manager should go first currentManagerTurnPointer = SelectStartingManager(); // Get fantasy teams allFantasyTeams = fantasyTeamRepository.GetAllFantasyTeams(); // Resetting any previous team selections playerRepository.ResetFantasyTeamSelection(); StageManagementWrapper(stages, selectablePlayersAdapter, allFantasyTeams); ArrangeNewTurn(selectablePlayersAdapter, allFantasyTeams); string currentManagerFirstName = allFantasyTeams[currentManagerTurnPointer].ManagerFirstname; string currentManagerSurname = allFantasyTeams[currentManagerTurnPointer].ManagerSurname; string currentFantasyTeamName = allFantasyTeams[currentManagerTurnPointer].FantasyTeamName; currentManagerTurnTextView.Text = NameTeamTextFormatting.FormatNameAndTeam(currentManagerFirstName, currentManagerSurname, currentFantasyTeamName); remainingFantasyTeamBalance.Text = fantasyTeamRepository.GetRemainingFantasyTeamCost(allFantasyTeams[currentManagerTurnPointer].FantasyTeamID).ToString(); selectablePlayersList.ItemSelected += (sender, args) => { selectedPlayer = selectablePlayersAdapter[args.Position]; }; nextTurnButton.Click += (sender, args) => { selectedPlayer.FantasyTeamID = allFantasyTeams[currentManagerTurnPointer].FantasyTeamID; playerRepository.UpdatePlayer(selectedPlayer); // Deselect item when turn is finished if (selectablePlayersList.CheckedItemPositions != null) { selectablePlayersList.CheckedItemPositions.Clear(); nextTurnButton.Enabled = false; } if (turnCounter == 2) { // Checking if there are uncompleted stages left if (stages.Count != 0) { StageManagementWrapper(stages, selectablePlayersAdapter, allFantasyTeams); turnCounter += 1; } else { StartActivity(typeof(DisplayTeamsActivity)); Finish(); } } else { currentManagerTurnPointer = currentManagerTurnPointer ^ 1; // Go to next turn ArrangeNewTurn(selectablePlayersAdapter, allFantasyTeams); } currentManagerFirstName = allFantasyTeams[currentManagerTurnPointer].ManagerFirstname; currentManagerSurname = allFantasyTeams[currentManagerTurnPointer].ManagerSurname; currentFantasyTeamName = allFantasyTeams[currentManagerTurnPointer].FantasyTeamName; currentManagerTurnTextView.Text = NameTeamTextFormatting.FormatNameAndTeam(currentManagerFirstName, currentManagerSurname, currentFantasyTeamName); remainingFantasyTeamBalance.Text = fantasyTeamRepository.GetRemainingFantasyTeamCost(allFantasyTeams[currentManagerTurnPointer].FantasyTeamID).ToString(); // Data will have changed so list view needs refreshing - player selected or new stage, one or both selectablePlayersAdapter.NotifyDataSetChanged(); }; selectablePlayersList.ItemClick += (sender, args) => { // Enable next turn button now a player has been selected nextTurnButton.Enabled = true; GetSelectedPlayer(args, selectablePlayersAdapter); }; }