我在android活动中有一个numberpicker控件。单击“+”和“ - ”按钮时效果很好。但是当我从键盘输入一个数字并尝试在程序中获取当前输入的值时,它不会给出键盘输入的值。我正在使用C#Xamarin android。
是否有任何关键的新闻事件或其他可以提供帮助的内容?
答案 0 :(得分: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();
}
}