EditText在第一次焦点时切换键盘类型

时间:2014-02-20 15:02:26

标签: android focus android-edittext

我有一个带有数值的EditText,并且inputType设置为number。当我点击它时,它会打开带有数字布局的键盘,1秒后它会切换到完整的字母键盘。如果我再次选择已打开键盘的EditText,它将返回正确的数字布局。 如果我关闭键盘并再次打开它,我又会遇到同样的问题。

我不知道为什么。

这是EditText:

<EditText
android:id="@+id/et_reservation_quantity_picker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:background="@null"
android:gravity="center"
android:inputType="number"
android:maxWidth="80dp"
android:minWidth="25dp"
android:text="1"
android:textSize="20dp" />

它位于ListView内。

这是代码(它在C#中,抱歉):

在GetView中(我不回收视图):

EditText etQuantityPicker = ((EditText)v.FindViewById (Resource.Id.et_reservation_quantity_picker));
etQuantityPicker.AddTextChangedListener (new SingleTextWatcher (item, _vm, etQuantityPicker));
etQuantityPicker.Text = item.Quantity + "";

听众:

class SingleTextWatcher : Java.Lang.Object, ITextWatcher
    {
        ReservationCellViewModel _item;
        ReservationsModificationViewModel _vm;
        EditText _etQuantityPicker;

        public SingleTextWatcher(ReservationCellViewModel item, ReservationsModificationViewModel vm, EditText etQuantityPicker)
        {
            _item = item;
            _vm = vm;
            _etQuantityPicker = etQuantityPicker;
        }

        public void AfterTextChanged (IEditable s)
        {
            string currentValue = s.ToString();
            int workingInt;
            if(string.IsNullOrEmpty(currentValue))
            {

            }
            else if(int.TryParse(currentValue, out workingInt))
            {
                _item.Quantity = workingInt;
                if(_item.Stock > 0 && _item.Quantity>_item.Stock)
                    _item.Quantity = _item.Stock;
            }
        }

        public void BeforeTextChanged (ICharSequence s, int start, int count, int after)
        {

        }

        public void OnTextChanged (ICharSequence s, int start, int before, int count)
        {

        }
    }

1 个答案:

答案 0 :(得分:0)

实际上我不知道C#你可以使用ViewHolder

during the scrolling of ListView 经常调用findViewById() (inflated layout's children is inflated for a row of listview),这会降低性能。即使适配器返回recycling的虚增视图,您仍需要look up the elements and update them。绕过重复使用findViewById()的方法是使用view holder design pattern

ViewHolder对象存储component views inside the tag field of the Layout中的每一个,因此您可以immediately access them without the need to look them up repeatedly。首先,您需要创建一个类来保存您的确切视图集。

了解更多信息Visit here

http://developer.android.com/training/improving-layouts/smooth-scrolling.html