private void LoadDaySelectorButtons(int type = 1) { layoutButtons = FindViewById <LinearLayout>(Resource.Id.layout_buttons); layoutButtons.RemoveAllViews(); var layoutButtonParams = new LinearLayoutCompat.LayoutParams( (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 40, Resources.DisplayMetrics), (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 40, Resources.DisplayMetrics)) { Width = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 40, Resources.DisplayMetrics), Height = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 40, Resources.DisplayMetrics), MarginEnd = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 5, Resources.DisplayMetrics) }; int dayIndex = ReturnDayIndex(); DateTime baseDate = DateTime.Today; // var today = baseDate; // var yesterday = baseDate.AddDays(-1); DateTime thisWeekStart = baseDate.AddDays(-dayIndex); // var thisWeekEnd = thisWeekStart.AddDays(7).AddSeconds(-1); // var lastWeekStart = thisWeekStart.AddDays(-7); // var lastWeekEnd = thisWeekStart.AddSeconds(-1); DateTime thisMonthStart = baseDate.AddDays(1 - baseDate.Day); // var thisMonthEnd = thisMonthStart.AddMonths(1).AddSeconds(-1); // var lastMonthStart = thisMonthStart.AddMonths(-1); // var lastMonthEnd = thisMonthStart.AddSeconds(-1); switch (type) { case 1: GetDataForChart(thisWeekStart, _dataType == "BloodPressure"); break; case 2: GetDataForChart(thisMonthStart, _dataType == "BloodPressure"); break; case 3: GetDataForChart(new DateTime(DateTime.Now.Year, 1, 1), _dataType == "BloodPressure"); break; default: return; } if (type != 3) { string[] days = { "L", "M", "M", "J", "V", "S", "D" }; int dayOfMonth = DateTime.Now.Day; int numberOfDaysInMonth = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month); int size = type == 1 && type != 3 ? days.Length : numberOfDaysInMonth; var activeButton = new AppCompatButton(this); for (var i = 0; i < size; i++) { bool isActive = type == 1 && type != 3 ? i == dayIndex : i + 1 == dayOfMonth; AppCompatButton btn = DaySelectorButton(isActive); btn.Id = i + 1; btn.Text = type == 1 && type != 3 ? i < days.Length ? days[i] : i.ToString() : (i + 1).ToString(); btn.LayoutParameters = layoutButtonParams; if (type == 1 && type != 3 && i > dayIndex) { btn.Enabled = false; btn.SetTextColor(Resources.GetColor(Resource.Color.colorSecondary, Theme)); } else if (i + 1 > dayOfMonth) { btn.Enabled = false; btn.SetTextColor(Resources.GetColor(Resource.Color.colorSecondary, Theme)); } if (isActive) { activeButton = btn; } layoutButtons.AddView(btn); } if (type == 2) { _scrollViewButtons.PostDelayed(delegate { _scrollViewButtons.SmoothScrollTo(activeButton.Left - 5, 0); }, 30); } } else { Drawable img = Resources.GetDrawable(Resource.Drawable.calendar_date, Theme); img.SetBounds(0, 0, 50, 50); var btn = new AppCompatButton(this) { Id = 1, Text = "Data" //Background = buttonBackgroundA, //LayoutParameters = layoutButtonParams }; btn.SetTextColor(Color.White); btn.Background = buttonBackgroundDatePicker; btn.SetAllCaps(false); btn.SetCompoundDrawables(img, null, null, null); btn.SetPadding((int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 8, Resources.DisplayMetrics), (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 8, Resources.DisplayMetrics), (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 8, Resources.DisplayMetrics), (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 8, Resources.DisplayMetrics)); btn.Click += (sender, args) => { var frag = SharingDatePickerFragment.NewInstance(delegate(DateTime time) { //_tbDate.Text = time.ToShortDateString(); _tvDate.Text = time.ToShortDateString(); switch (_dataType) { case "BloodPressure": verticalScrollLinearLayout.RemoveAllViewsInLayout(); horizontalScrollLinearLayout.RemoveAllViewsInLayout(); LoadDataInScrollLayouts(time); break; case "BloodGlucose": verticalScrollLinearLayout.RemoveAllViewsInLayout(); LoadDataInScrollLayouts(time, false); break; } }); frag.Show(SupportFragmentManager, SharingDatePickerFragment.TAG); }; layoutButtons.AddView(btn); } }