Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
314 views
in Technique[技术] by (71.8m points)

xml - 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

question from:https://stackoverflow.com/questions/65896439/how-to-set-big-integer-in-android-layout-textview

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

editId.setText(st_id + "");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...