首页 > 解决方案 > 如何在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 天新。

谢谢

标签: androidxmlkotlinlayoutnumbers

解决方案


解决方案是将其设置为字符串。
只需将该行修改为:

editId.setText(st_id + "");

推荐阅读