gpt4 book ai didi

android - 当 inputType 属性设置为 'number' 时,如何在 EditText 中使用逗号分隔符?

转载 作者:行者123 更新时间:2023-11-30 01:46:12 25 4
gpt4 key购买 nike

我想创建一个只允许输入数字的 EditText 数组。我想用逗号分隔数字。我使用以下代码创建了 EditText 数组并且键盘行为发生了变化,但是当我按下逗号键时没有任何反应。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:shrinkColumns="*"
android:stretchColumns="*">
<TableRow
android:id="@+id/tableRow4"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:hint="max."
android:gravity="center"
android:ems="4"
android:id="@+id/editText"/>
</TableRow>

</TableLayout>


</RelativeLayout>

最佳答案

你必须使用这种输入类型:

InputType.TYPE_NUMBER_FLAG_DECIMAL

或者在 xml 中:

android:inputType="numberDecimal"

关于android - 当 inputType 属性设置为 'number' 时,如何在 EditText 中使用逗号分隔符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33687697/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com