2013-03-18 60 views
0

我想制作一个格式如下的EditText字段:0000 AA。EditText输入格式

是否可以让数字键盘出现在第4个数字,然后自动创建一个空间,然后使正常的键盘出现?

我该怎么用C#做到这一点?

有人想法?

回答

2

这应该做的伎俩:

EditText zipcode = FindViewById<EditText>(Resource.Id.zipcode); 
zipcode.InputType = Android.Text.InputTypes.ClassNumber; 
bool numberMode = true; 
zipcode.TextChanged += (object sender, Android.Text.TextChangedEventArgs e) => { 
    if(zipcode.Text.Length == 4){ 
     if(numberMode){ 
      numberMode = false; 
      zipcode.Text = zipcode.Text + " "; 
      zipcode.SetSelection(zipcode.Text.Length); 
     } 
    } 

    if(zipcode.Text.Length > 4){ 
     numberMode = false; 
     zipcode.InputType = Android.Text.InputTypes.ClassText; 
    } 

    if(zipcode.Text.Length <= 4){ 
     numberMode = true; 
     zipcode.InputType = Android.Text.InputTypes.ClassNumber; 
    } 
}; 
+0

也看看:http://forums.xamarin.com/discussion/comment/6914/#Comment_6914该做类似的事情。 – Cheesebaron 2013-03-18 13:18:04