EditText上不接受数字输入 [英] EditText does not accept digits as input
问题描述
在的EditText
视图 ID =价格
有一个 inputType =numberDecimal
不接受任何数字,但只接受小数点后一位数。另的EditText
视图 ID =存储
没有 inputType
确定,但有两个问题。如果视图没有输入,然后进入键盘数字没有做任何事情。有一个数字被接受的唯一方法是,如果它紧跟字母或其它数字。我使用的是默认的安卓
键盘。布局正在膨胀中的 onCreateView()
SherlockFragment
的子类的方法。难道这是一个问题,在的EditText
视图的行为 SherlockFragment
?我有一个用于膨胀SherlockFragmentActivity的一个子类相似的布局,以及的EditText
的意见都将正常进行。有谁知道什么可能会造成这个问题?
The EditText
view with id="price"
has an inputType="numberDecimal"
that does not accept any digits but will only accept one decimal point. The other EditText
view with id="store"
has no inputType
set but has two issues. If the view has no input then entering a digit from the keyboard doesn't do anything. The only way to have a digit be accepted is if it immediately follows either a letter or another digit. I am using the default Android
keyboard. The layout is being inflated in the onCreateView()
method of a subclass of SherlockFragment
. Could this be an issue with the EditText
view behavior inside a SherlockFragment
? I have a similar layout that is used to inflate a subclass of 'SherlockFragmentActivity', and those EditText
views behave normally. Does anyone know what could be causing this issue?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
style="@style/ProductTextViewTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="Product Tile" />
<TableRow android:layout_width="fill_parent"
android:layout_height="50dp"
android:gravity="center_vertical"
android:padding="5dp">
<TextView
style="@style/ApolloStyleBold"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.4"
android:gravity="center_vertical"
android:paddingLeft="5dp"
android:text="@string/price"/>
<EditText android:id="@+id/price"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.6"
android:background="@null"
android:hint="@string/price_italic_hint"
android:inputType="numberDecimal"/>
</TableRow>
<TableRow android:layout_width="fill_parent"
android:layout_height="50dp"
android:gravity="center_vertical"
android:padding="5dp">
<TextView
style="@style/ApolloStyleBold"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.4"
android:gravity="center_vertical"
android:paddingLeft="5dp"
android:text="@string/store_name"/>
<EditText android:id="@+id/store"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.6"
android:background="@null"
android:hint="@string/stores_hint"
/>
</TableRow>
</LinearLayout>
更新
当我测试了在Android V4.3,它具有搞砸了(不接受数字输入)的行为。不过,我测试了它在Android V4.1.2,它接受数字输入。有什么关于这两个版本的不同,只要EditText上的行为?
Update
When I tested this on Android v4.3, it has the messed up (not accepting digits as input) behavior. However, I tested it on Android v4.1.2, and it accepts digits as input. Is there something different about these two versions as far as EditText behavior?
推荐答案
原来,这个问题是不是与安卓inputType
设置的,但有一个较高的ViewGroup在视图层次结构。这是用来充气的布局 SherlockFragment
是一个孩子在一个更复杂的布局。
It turns out the issue wasn't with the android:inputType
that was set, but with a ViewGroup higher up in the view hierarchy. The layout which is used to inflate the SherlockFragment
was a child in a more complex layout.
几个家长了视图层次存在的的FrameLayout
的ViewGroup的子类名为 DragLayer
。该 DragLayer
类实现的接口
名为 DragController.DragListener
这有一个方法 dispatchKeyEvent(KeyEvent的事件)
。这种方法在 DragLayer
使用 @覆盖
标记但没有叫 super.dispatchKeyEvent(事件)
。加入这一行的code后,然后单击键盘上的数字的事件没有得到消耗,所有的工作了。
A few parents up the view hierarchy there was a subclass of the FrameLayout
ViewGroup called DragLayer
. The DragLayer
class implemented an Interface
called DragController.DragListener
which has a method dispatchKeyEvent(KeyEvent event)
. This method in DragLayer
uses the @Override
notation however did not call super.dispatchKeyEvent(event)
. After adding this line of code, then the event of clicking a digit on the keyboard did not get consumed and all works now.
这篇关于EditText上不接受数字输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!