android - 如何在android布局textview中设置大整数?
问题描述
我需要在 android studio 中为特定字段设置文本。它被称为editID。现在,ID 是数字,它只能是数字。因此,我将其输入类型设置为数字。但是,我需要从 android studio 代码中为其设置一个整数值。这是editID组件的片段:
android:autofillHints=""
android:ems="10"
android:hint="@string/student_id"
android:inputType="number"
android:textAlignment="center"
android:visibility="invisible"
现在在我的代码的实际 kotlin 类中,我有这一点:
val st_id = item.st_id.toBigInteger() //Here I cast the value to Big Integer
val st_name = item.st_name
val message = "Are you " + st_name + " " + st_id + " ?" // Here in this message the number shows fine
MaterialAlertDialogBuilder(this)
.setTitle(resources.getString(R.string.confirmTitle))
.setMessage(message)
.setNeutralButton(resources.getString(R.string.cancel)) { dialog, which ->
dialog.dismiss()
}
.setNegativeButton(resources.getString(R.string.decline)) { dialog, which ->
dialog.dismiss()
editName.setText(st_name)
editId.setText(st_id) //But, here is the issue
with(motion_layout as MotionLayout) {
setTransition(R.id.end, R.id.firstLogin)
transitionToEnd()
如果您查看我的评论,则问题出在 setText。每当应用程序到达这段代码时,应用程序就会崩溃并显示“找不到资源@#XXXXXXXXX”的错误消息,并且日志将我准确地指向这一行。
如果我没有错,那么我的问题就是问题的原因。而且我在任何地方都找不到任何解决方案。我不想在这里输入类型文本。因为对于用户来说,我需要出现仅数字键盘。如果你们有任何解决方案,它会有所帮助。此外,我对 Kotlin 完全陌生,比如 2 天新。
谢谢
解决方案
解决方案是将其设置为字符串。
只需将该行修改为:
editId.setText(st_id + "");
推荐阅读
- reactjs - 反应:使用componentDidMount()的脚本“编译失败”
- angular - 在嵌套的 FormArray 中查找最小值
- azureservicebus - MassTransit - 知道 IConsumeObserver.ConsumeFault 何时被调用或退出重试
- android - 颤振行间隔因语言而异
- c - 到达/离开程序
- bash - 如果 && 中发生错误并使用 set -e,则脚本继续
- wso2 - 在 wso2 API 货币化中,为什么订阅者将填写有关计划的详细信息
- tensorflow - 为什么 tensorflow 默认不使用 flatbuffers
- python - 使用任意数量的列自动连接?
- xml - 在 Visual Studio 2017 中使用标准 XSD 架构验证 XML