Beispiel #1
0
        public virtual bool SetText(string text, string alignment = null)
        {
            AlignText(alignment);

            if (ViewX is Button)
            {
                ((Button)ViewX).Text = text;
            }
            else if (ViewX is TextView)
            {
                ((TextView)ViewX).Text = text;
            }
            else if (ViewX is EditText)
            {
                ((EditText)ViewX).Text = text;
            }
            else if (ViewX is Spinner)
            {
                Spinner          spinner = ViewX as Spinner;
                TextImageAdapter adapter = spinner.Adapter as TextImageAdapter;
                if (adapter != null)
                {
                    int pos = adapter.Text2Position(text);
                    spinner.SetSelection(pos);
                }
            }
            else if (ViewX is NumberPicker)
            {
                NumberPicker  picker = ViewX as NumberPicker;
                string[]      all    = picker.GetDisplayedValues();
                List <string> names  = new List <string>(all);
                int           row    = names.FindIndex((obj) => obj.Equals(text));
                picker.Value = (int)row;
                ExecuteAction(row.ToString());
            }
            else
            {
                return(false);
            }

            return(true);
        }
Beispiel #2
0
        public virtual string GetText()
        {
            string text = "";

            if (ViewX is Button)
            {
                text = ((Button)ViewX).Text;
            }
            else if (ViewX is TextView)
            {
                text = ((TextView)ViewX).Text;
            }
            else if (ViewX is EditText)
            {
                text = ((EditText)ViewX).Text;
            }
            else if (ViewX is Spinner)
            {
                Spinner          spinner = ViewX as Spinner;
                TextImageAdapter adapter = spinner.Adapter as TextImageAdapter;
                if (adapter != null)
                {
                    int pos = spinner.SelectedItemPosition;
                    text = adapter.Position2Text(pos);
                }
            }
            else if (ViewX is NumberPicker)
            {
                NumberPicker picker = ViewX as NumberPicker;
                string[]     all    = picker.GetDisplayedValues();
                int          row    = picker.Value;
                if (all.Length > row && row >= 0)
                {
                    text = all[row];
                }
            }
            return(text);
        }