too*_*o42 6 android android-edittext actionbarsherlock
在EditText与观点id="price"有一个inputType="numberDecimal"不接受任何数字,但只接受一个小数点.另一个EditText视图id="store"没有inputType设置,但有两个问题.如果视图没有输入,则从键盘输入数字不会执行任何操作.接受数字的唯一方法是紧跟一个字母或另一个数字.我正在使用默认Android键盘.布局在onCreateView()子类的方法中被夸大了SherlockFragment.这可能是一个问题与EditText内部的视图行为SherlockFragment?我有一个类似的布局用于膨胀'SherlockFragmentActivity'的子类,这些EditText视图表现正常.有谁知道可能导致这个问题的原因是什么?
<?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>
Run Code Online (Sandbox Code Playgroud)
当我在Android v4.3上测试它时,它有混乱(不接受数字作为输入)行为.但是,我在Android v4.1.2上测试了它,它接受数字作为输入.就EditText行为而言,这两个版本有什么不同吗?
事实证明,问题不在于android:inputType设置的内容,而在于视图层次结构中较高的 ViewGroup。用于膨胀的布局SherlockFragment是更复杂布局中的子布局。
在视图层次结构的一些父级中,有一个FrameLayout名为 ViewGroup的子类DragLayer。该类DragLayer实现了一个具有方法的Interface调用。该方法使用了符号但是没有调用。添加这行代码后,单击键盘上的数字的事件不会被消耗,现在一切正常。DragController.DragListenerdispatchKeyEvent(KeyEvent event)DragLayer@Overridesuper.dispatchKeyEvent(event)