private void btn_save_Click(object sender, EventArgs e) { // If text contains characters if (txt_Name_.Text.Length > 0) { // Name=textfield HangmanGame.PlayerName = txt_Name_.Text.ToString(); // default score 0 HangmanGame.score = 0; var cc = new Db_Connection(); // Insert the name and score into the table of sqlite database cc.InsertNewPlayer(HangmanGame.PlayerName, HangmanGame.score); // Show all list List_Names = cc.ViewAll(); var da = new Resources.DataAdapter(this, List_Names); // Data In spinner Name_Score_Spinner.Adapter = da; } // If text name is blank else { Toast.MakeText(this, "Please Fill Name", ToastLength.Short).Show(); } }
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 HangmanGame.PlayerName = txtEnterPlayerName.Text.ToString(); // Give them a score of 0 to begin with HangmanGame.score = 0; var cc = new ConnectionClass(); // Insert the Players name and score into the database cc.InsertNewPlayer(HangmanGame.PlayerName, HangmanGame.score); // And update the list myList = cc.ViewAll(); var da = new Resources.DataAdapter(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(); } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.New_Palyer); Db_Connection myConnectionClass = new Db_Connection(); List_Names = myConnectionClass.ViewAll(); Name_Score_Spinner = FindViewById <Spinner>(Resource.Id.Spinnner_select); Hangman.Resources.DataAdapter da = new Resources.DataAdapter(this, List_Names); Name_Score_Spinner.Adapter = da; Name_Score_Spinner.ItemSelected += new EventHandler <AdapterView.ItemSelectedEventArgs>(spinner_ItemSelected); txt_Name_ = FindViewById <TextView>(Resource.Id.txt_Name); Button btn_Play_Game = FindViewById <Button>(Resource.Id.btn_Play_Game); btn_Play_Game.Click += btn_Play_Game_Click; Button btn_save = FindViewById <Button>(Resource.Id.btn_save); btn_save.Click += btn_save_Click; Button btn_Home_Page = FindViewById <Button>(Resource.Id.btn_Home_Page); btn_Home_Page.Click += btn_Home_Page_Click; }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.SelectPlayer); ConnectionClass myConnectionClass = new ConnectionClass(); myList = myConnectionClass.ViewAll(); PlayerNameSpinner = FindViewById <Spinner>(Resource.Id.selectPlayerSpinner); Hangman.Resources.DataAdapter da = new Resources.DataAdapter(this, myList); PlayerNameSpinner.Adapter = da; PlayerNameSpinner.ItemSelected += new EventHandler <AdapterView.ItemSelectedEventArgs>(spinner_ItemSelected); txtEnterPlayerName = FindViewById <TextView>(Resource.Id.txtEnterName); Button btnStartGame = FindViewById <Button>(Resource.Id.btnStartGame); btnStartGame.Click += btnStartGame_Click; Button btnAddPlayer = FindViewById <Button>(Resource.Id.btnAddProfile); btnAddPlayer.Click += btnAddPlayer_Click; Button btnselectplayerMainMenu = FindViewById <Button>(Resource.Id.btnselectplayerMainMenu); btnselectplayerMainMenu.Click += btnselectplayerMainMenu_Click; }