how to set only numeric value for EditTextPreference in android?

前端 未结 6 2079
轻奢々
轻奢々 2020-12-15 15:15

how to set only numeric value for EditTextPreference in android. I want a user to enter a port number not sure how can I put the limitation there

I am using this co

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-15 15:40

    Kotlin Code which worked for me:

    Here "editTextPrefSleepTime" is a key of EditTextPreference, which I set on xml file.

        private var editTextPrefSleepTime: EditTextPreference? = null
    
         override fun onStart() {
             super.onStart()
             editTextPrefSleepTime = preferenceManager.findPreference("editTextPrefSleepTime")
             editTextPrefSleepTime?.setOnBindEditTextListener {
                 it.inputType = InputType.TYPE_CLASS_NUMBER
             }
         }
    

提交回复
热议问题