如何在 android 布局文本视图中设置大整数?
How to set big integer in android layout textview?
我需要在 android studio 中为特定字段设置文本。它称为编辑 ID。现在,ID 是数字,只能是数字。因此,我将其输入类型设置为数字。但是,我需要从 android 工作室代码中为其设置一个整数值。这是 editID 组件的片段:
android:autofillHints=""
android:ems="10"
android:hint="@string/student_id"
android:inputType="number"
android:textAlignment="center"
android:visibility="invisible"
现在在我的代码的实际 kotlin class 中我有这个位:
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 + "");
您不能在 android 中的 TextView 上直接设置整数。下面是一些将整数值更改为字符串的代码:
String.valueOf(IntegerValue);
或
editId.setText(IntegerValue + "");
我需要在 android studio 中为特定字段设置文本。它称为编辑 ID。现在,ID 是数字,只能是数字。因此,我将其输入类型设置为数字。但是,我需要从 android 工作室代码中为其设置一个整数值。这是 editID 组件的片段:
android:autofillHints=""
android:ems="10"
android:hint="@string/student_id"
android:inputType="number"
android:textAlignment="center"
android:visibility="invisible"
现在在我的代码的实际 kotlin class 中我有这个位:
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 + "");
您不能在 android 中的 TextView 上直接设置整数。下面是一些将整数值更改为字符串的代码:
String.valueOf(IntegerValue);
或
editId.setText(IntegerValue + "");