protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_main); // changing CultureInfo to en-GB to show decimal point as "." instead of "," Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB"); // creating an array of 36 TextViews used for storing every cell from TableLayout int textViewCount = 36; textViewArray = new TextView[textViewCount]; // assigning resources to local variables Spinner spinner = FindViewById <Spinner>(Resource.Id.spinnerPrimaryType); Spinner spinner2 = FindViewById <Spinner>(Resource.Id.spinnerSecondaryType); Button showDmgButton = FindViewById <Button>(Resource.Id.showDmgButton); TableLayout tableLayout1 = FindViewById <TableLayout>(Resource.Id.tableLayout1); Android.Support.V7.Widget.Toolbar toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar); SetSupportActionBar(toolbar); // filling textViewArray with TextViews from TableLayout int y = 0; for (int i = 1; i < tableLayout1.ChildCount; i++) { View child = tableLayout1.GetChildAt(i); if (child is TableRow row) { for (int x = 0; x < row.ChildCount; x++) { View view = row.GetChildAt(x); textViewArray[y] = (TextView)view; ++y; } } } // restoring saved data when screen orientation is changed if (savedInstanceState != null) { string[] temp = savedInstanceState.GetStringArray("savedArray"); int[] tempColors = savedInstanceState.GetIntArray("savedColors"); selectedSorting = savedInstanceState.GetInt("savedSorting"); for (int d = 0; d < 36; d++) { textViewArray[d].Text = temp[d]; Android.Graphics.Color backgroundColor = new Android.Graphics.Color(tempColors[d]); textViewArray[d].SetBackgroundColor(backgroundColor); } if (temp[0] != "") { tableLayout1.SetColumnCollapsed(0, false); tableLayout1.SetColumnCollapsed(1, false); } } // creating 2 custom spinner adapters and assigning them to the primary and secondary pokemon type spinners ColorfulSpinnerAdapter adapter = new ColorfulSpinnerAdapter(this, Resource.Array.pokemonType, Resource.Layout.spinner_item); ColorfulSpinnerAdapter adapter2 = new ColorfulSpinnerAdapter(this, Resource.Array.pokemonType, Resource.Layout.spinner_item); spinner.Adapter = adapter; spinner2.Adapter = adapter2; // creating local variables used for filling TextViews string type1 = string.Empty; string type2 = string.Empty; TypeCalculator dmgCalc = new TypeCalculator(); PkmnType[] typez; PkmnType[] typez2; showDmgButton.Click += (sender, e) => { // checks spinner content type1 = spinner.SelectedItem.ToString(); type2 = spinner2.SelectedItem.ToString(); // check if one of chosen types is (none) if (string.Equals(type1, Resources.GetString(Resource.String.notype))) { if (string.Equals(type2, Resources.GetString(Resource.String.notype))) { // fill TextViews of TableLayout with empty strings if both chosen types are (none) for (int d = 0; d < textViewCount; d++) { textViewArray[d].Text = ""; } // hide table tableLayout1.SetColumnCollapsed(0, true); tableLayout1.SetColumnCollapsed(1, true); } else { // if the secondary type is not (none) check type and start filling table with sorted values typez = dmgCalc.CheckType(type2); // check selected sorting option if (selectedSorting == menu.GetItem(2).ItemId) { typez = dmgCalc.SortPkmnTypes(typez); } else if (selectedSorting == menu.GetItem(1).ItemId) { typez = dmgCalc.SortPkmnTypesByName(typez); } for (int d = 0, t = 0; d < textViewCount - 1; d += 2, t++) { textViewArray[d].Text = typez[t].TypeName; textViewArray[d].SetBackgroundColor(typez[t].TypeColor); textViewArray[d + 1].SetBackgroundColor(typez[t].TypeColor); textViewArray[d + 1].Text = typez[t].DmgTaken.ToString() + "x"; } // show table tableLayout1.SetColumnCollapsed(0, false); tableLayout1.SetColumnCollapsed(1, false); } } else { // if secondary type equals (none) or both types are the same check only primary type dmg multipliers if (string.Equals(type2, Resources.GetString(Resource.String.notype)) || string.Equals(type2, type1)) { typez = dmgCalc.CheckType(type1); // check selected sorting option if (selectedSorting == menu.GetItem(2).ItemId) { typez = dmgCalc.SortPkmnTypes(typez); } else if (selectedSorting == menu.GetItem(1).ItemId) { typez = dmgCalc.SortPkmnTypesByName(typez); } for (int d = 0, t = 0; d < textViewCount - 1; d += 2, t++) { textViewArray[d].Text = typez[t].TypeName; textViewArray[d].SetBackgroundColor(typez[t].TypeColor); textViewArray[d + 1].SetBackgroundColor(typez[t].TypeColor); textViewArray[d + 1].Text = typez[t].DmgTaken.ToString() + "x"; } } else { // if both types are different and none of them equals (none) check both types and // multiply primary type multipliers by secondary type multipliers typez = dmgCalc.CheckType(type1); typez2 = dmgCalc.CheckType(type2); for (int i = 0; i < 18; ++i) { typez[i].DmgTaken *= typez2[i].DmgTaken; } // check selected sorting option if (selectedSorting == menu.GetItem(2).ItemId) { typez = dmgCalc.SortPkmnTypes(typez); } else if (selectedSorting == menu.GetItem(1).ItemId) { typez = dmgCalc.SortPkmnTypesByName(typez); } for (int d = 0, t = 0; d < textViewCount - 1; d += 2, t++) { textViewArray[d].Text = typez[t].TypeName; textViewArray[d].SetBackgroundColor(typez[t].TypeColor); textViewArray[d + 1].SetBackgroundColor(typez[t].TypeColor); textViewArray[d + 1].Text = typez[t].DmgTaken.ToString() + "x"; } } tableLayout1.SetColumnCollapsed(0, false); tableLayout1.SetColumnCollapsed(1, false); } }; }