【问题标题】:edit text not accepting numbers , accepts only alphabets (no input type is set)编辑文本不接受数字,只接受字母(未设置输入类型)
【发布时间】:2021-04-06 19:28:05
【问题描述】:

<TextView
    style="@style/ProductTextViewTitle"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="10dp"
    android:text="Add a Price at a Local Store" />

<TableRow
    android:layout_width="fill_parent"
    android:layout_height="50dp"
    android:gravity="center_vertical"
    android:padding="5dp" >

    <TextView
         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>

<TableRow
    android:layout_width="fill_parent"
    android:layout_height="50dp"
    android:gravity="center_vertical"
    android:padding="5dp" >

    <TextView
        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/no_prices_found"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="0.6"
        android:background="@null"
        android:hint="@string/price_italic_hint" >

    </EditText>
</TableRow>

<TableRow
    android:layout_width="fill_parent"
    android:layout_height="50dp"
    android:layout_marginTop="5dp"
    android:gravity="center_vertical"
    android:padding="5dp" >

    <Button
        android:id="@+id/submit"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:text="Add price"
        android:textStyle="italic" />
</TableRow>

id ="no_prices_found" 的编辑文本不接受任何数字,但接受特殊字符和字母。关于在 android 中编辑文本的这种奇怪行为的任何线索。名为编辑文本的“商店”行为正常。

===== 注意====== 此布局在用作其父片段中使用的片段布局时工作正常。知道父母的什么行为可能导致这种情况吗?

【问题讨论】:

  • 你是否在代码中设置了任何属性?
  • 什么都没有。没有请求焦点,输入类型等
  • 我看到的唯一区别是您使用结束 /> 为一个,而 为另一个,但这无关紧要。试试把出错的那个xml剪掉,保存,十个贴回去。
  • works fine when it is used as fragment layout 是什么意思?能否请您也发布整个布局文件?
  • 我在这里做类似的事情!!! stackoverflow.com/questions/18069507/…

标签: android android-layout android-edittext


【解决方案1】:

当我的 EditText 被放置在 Dialog 布局中时,我遇到了类似的问题,并且我无法在该字段中输入任何数字(字母和其他字符确实可以正常工作),更改 inputType 没有帮助。

我意识到我为我的 Dialog 使用了自定义 OnKeyListener,这就是问题所在 - 必须从内部返回 false,以防按下的键应正确传递给 Dialog 的子项(包括 EditText)。然后我的 EditText 又开始正常工作了。

【讨论】:

    【解决方案2】:

    我遇到了类似的问题。问题是在不满足条件时消耗 OnKeyListener 中的事件(按下的键未输入)。这导致没有将 onKey 事件传递给系统。返回false 完成了这项工作。

    有关 Android 事件处理的更多信息,您可以找到 here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-26
      • 1970-01-01
      • 2021-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多