【问题标题】:NumberPicker does not work with keyboard input value in Xamarin AndroidNumberPicker 不适用于 Xamarin Android 中的键盘输入值
【发布时间】:2015-01-30 20:57:25
【问题描述】:

我在 android 活动中有一个数字选择器控件。单击那些“+”和“-”按钮时效果很好。但是当我从键盘输入一个数字并尝试在程序中获取当前输入的值时,它不会给出通过键盘输入的值。我正在使用 C# Xamarin android。

是否有任何按键事件或可以提供帮助的东西?

【问题讨论】:

    标签: c# android xamarin


    【解决方案1】:

    您可以在 NumberPicker 的 EditText 上创建自定义 OnEditorActionListener:

    NumberPicker picker;
    protected override void OnCreate(Bundle bundle)
            {
                base.OnCreate(bundle);
                SetContentView(Resource.Layout.test);
                picker  = FindViewById<NumberPicker>(Resource.Id.numberPicker);
                picker.MaxValue = 40;
                picker.MinValue = 1;
                EditText editText= (EditText)picker.GetChildAt(1);
                editText.SetOnEditorActionListener(new CustomActionListener());
    
            }
    
     public class CustomActionListener : Java.Lang.Object,EditText.IOnEditorActionListener
            {
    
                public bool OnEditorAction(TextView v, Android.Views.InputMethods.ImeAction actionId, KeyEvent e)
                {
    
                    if(actionId == Android.Views.InputMethods.ImeAction.Done)
                    {
                        // Here is you number
                        string countNumber = v.Text;
                    }
                    return true;
    
                }
    
                public IntPtr Handle
                {
                    get { return base.Handle; }
                }
    
                public void Dispose()
                {
                    base.Dispose();
                }
            }
    

    【讨论】:

      猜你喜欢
      • 2013-09-27
      • 2013-09-18
      • 2015-03-28
      • 1970-01-01
      • 2013-10-25
      • 1970-01-01
      • 2011-12-14
      • 1970-01-01
      • 2021-03-01
      相关资源
      最近更新 更多