public virtual void SetPlayers(List <Player> myCurrentPlayers) { myButtons.Clear(); Space space = new Space(Context) { LayoutParameters = new LayoutParams(0, 1, 1f) }; RemoveAllViews(); AddView(space); for (int i = 0; i < myCurrentPlayers.Count; i++) { ItemHolderRadioButton newButton = new ItemHolderRadioButton(Context, false) { LayoutParameters = new LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent), ItemId = myCurrentPlayers[i].Id, Text = myCurrentPlayers[i].Abbrevation }; AddView(newButton); myButtons.Add(newButton); AddView(new Space(Context) { LayoutParameters = new LayoutParams(0, 1, 1f) }); } }
private void MultiLineRadioGroup_ChildViewAdded(object sender, ChildViewAddedEventArgs e) { if (e.Child.GetType().Equals(typeof(LinearLayout))) { LinearLayout ll = e.Child as LinearLayout; SetRadioButtons(ll); } if (e.Child.GetType().Equals(typeof(ItemHolderRadioButton))) { ItemHolderRadioButton rb = e.Child as ItemHolderRadioButton; rb.CheckedChange += Rb_CheckedChange; myButtons.Add(rb); } }
private void SetRadioButtons(LinearLayout ll) { int count = ll.ChildCount; for (int i = 0; i < count; i++) { View o = ll.GetChildAt(i); if (o.GetType() == typeof(ItemHolderRadioButton)) { ItemHolderRadioButton rb = o as ItemHolderRadioButton; rb.CheckedChange += Rb_CheckedChange; myButtons.Add(rb); } } }
private void Rb_CheckedChange(object sender, CompoundButton.CheckedChangeEventArgs e) { if (!e.IsChecked) { return; } ItemHolderRadioButton checkedChangedButton = sender as ItemHolderRadioButton; myButtons.ForEach(rb => { if (rb.Id != checkedChangedButton.Id) { rb.Checked = false; } }); var test = myButtons.Where(b => b.Checked).ToList(); OnCheckedChanged(new CheckedChangeEventArgs(checkedChangedButton.Id)); }
public override void SetPlayers(List <Player> myCurrentPlayers) { int count = myCurrentPlayers.Count; int layoutCount = ChildCount; double doubleChild = Convert.ToDouble(count) / layoutCount; int childPerLayout = Convert.ToInt16(Math.Ceiling(doubleChild)); int playerIndex = 0; for (int child = 0; child < ChildCount; child++) { LinearLayout view = GetChildAt(child) as LinearLayout; view.RemoveAllViews(); for (int i = 0; i < childPerLayout; i++) { if (playerIndex >= count) { break; } var layoutParams = new LayoutParams(0, ViewGroup.LayoutParams.WrapContent, 1); layoutParams.SetMargins(15, 15, 15, 15); Player currentPlayer = myCurrentPlayers[playerIndex]; ItemHolderRadioButton newButton = new ItemHolderRadioButton(Context, true) { LayoutParameters = layoutParams, ItemId = currentPlayer.Id, Text = (currentPlayer.Number > -1 ? currentPlayer.Number + " " : "") + currentPlayer.FirstName, Id = GenerateViewId(), }; newButton.CheckedChange += Rb_CheckedChange; myButtons.Add(newButton); view.AddView(newButton); playerIndex++; } } }