private void btnAddPlayer_Click(object sender, EventArgs e) { // If the length of the text is more then 0.. do this.. if (txtEnterPlayerName.Text.Length > 0) { // Set the new PlayerName to the text in the textfield HomeScreen.PlayerName = txtEnterPlayerName.Text.ToString(); // Give them a score of 0 to begin with HomeScreen.score = 0; var cc = new DBConnection(); // Insert the Players name and score into the database String res = cc.InsertNewPlayer(HomeScreen.PlayerName, HomeScreen.score); // Toast.MakeText(this, txtEnterPlayerName.Text.ToString()+" "+ res, ToastLength.Short).Show(); // And update the list myList = cc.ViewAll(); //Toast.MakeText(this, txtEnterPlayerName.Text.ToString() + " " +myList.Count, ToastLength.Short).Show(); var da = new Resources.DBDA(this, myList); // And display the updated list on the spinner PlayerNameSpinner.Adapter = da; } // Display a message if there is an empty textfield else { Toast.MakeText(this, "Please enter at least 1 character for your name", ToastLength.Short).Show(); } }
private void btnAddPlayer_Click(object sender, EventArgs e) { if (txtEnterPlayerName.Text.Length > 0) { //Set the player name to the textbox Game.PlayerName = txtEnterPlayerName.Text; //Start with a score of 0 Game.Score = 0; myConnection = new DBConnection(); //Insert the player into the database using the InsertNewPlayer method and passing across the Game fields myConnection.InsertNewPlayer(Game.PlayerName, Game.Score, Game.DateTime); //Update the list and display on the spinner myList = myConnection.ViewAll(); da = new DataAdapter(this, myList); spnPlayerName.Adapter = da; Toast.MakeText(this, Game.PlayerName + " has been added", ToastLength.Short).Show(); } else // If the text field is empty, display error message { Toast.MakeText(this, "Please enter at least 1 character for your name.", ToastLength.Short).Show(); } }