예제 #1
0
        protected void ShowAlert(EditText editText, string alertText)
        {
            if (validationAlerts.ContainsKey(editText))
            {
                return;
            }

            var metrics       = GetDisplayMetrics();
            int layoutOffsetY = metrics.HeightPixels - rootLayout.Height;

            int[] editTextCoordinates = new int[2];
            editText.GetLocationOnScreen(editTextCoordinates);

            int xOffset = editTextCoordinates[0];
            int yOffset = editTextCoordinates[1] + editText.Height - GetPixelsFromDpi(17) - layoutOffsetY;

            var inflater = (LayoutInflater)this.GetSystemService(Context.LayoutInflaterService);
            var view     = inflater.Inflate(Resource.Layout.a_validationerror, null);

            view.FindViewById <TextView>(Resource.Id.errorMessage).Text = alertText;

            var lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WrapContent, RelativeLayout.LayoutParams.WrapContent);

            lp.LeftMargin = xOffset;
            lp.TopMargin  = yOffset;
            rootLayout.AddView(view, lp);

            validationAlerts.Add(editText, view);

            editText.FocusChange += HandleFocusChange;
        }