Anti-Ordinary Roy
Anti-Ordinary Roy

Reputation: 3

How to set big integer in android layout textview?

I need to set text for a particular field in android studio. It is called editID. Now, the ID is in numeric and it can be numbers only. Hence I have set the input type for that as number. But, i need to set an integer value to it from the android studio code. Here is a snippet of editID component:

android:autofillHints=""
    android:ems="10"
    android:hint="@string/student_id"
    android:inputType="number"
    android:textAlignment="center"
    android:visibility="invisible"

Now in the actual kotlin class of my code i have this bit:

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()

If you look at my comments the issue is at setText. Whenever the application gets to this bit of code, the app crashes with the error message of "Resource not found @#XXXXXXXXX" And the LOG points me to this Line exactly.

If i am not wrong then my question is the reason for the problem. And I cannot find any solution anywhere. I don't want to have Input Type Text here. Because for the user I need to have the Numeric Only Keyboard to come up. If you guys have any solution it would help. Also I am totally new to Kotlin like, 2 days new.

Thanks

Upvotes: 0

Views: 282

Answers (2)

Muhammad Asad
Muhammad Asad

Reputation: 668

You cannot set Directly Integer number on TextView in android. Here is some code to change the Integer value into String:

String.valueOf(IntegerValue);

or

editId.setText(IntegerValue + "");

Upvotes: 0

Yash
Yash

Reputation: 427

The solution is to set it as a String.
Just modify that line to this:

editId.setText(st_id + "");

Upvotes: 1

Related Questions