Home > Enterprise >  How to edit the text of a textView using viewbinding?
How to edit the text of a textView using viewbinding?

Time:10-19

I am new to kotlin and android and I just started getting into using viewbindings. Im trying to make this locations app and when setting the date through a datepickerdialog, when i try to edit the text of a textview with a binding its giving me errors. Can someone help me?

private fun displaySelectedDate(timestamp : Long){

    binding?.etDate?.text = format.format(timestamp)

CodePudding user response:

Change it to

binding?.etDate?.setText(format.format(timestamp))

CodePudding user response:

If you check the docs for EditText, you'll find a setText() method. It takes in a String and a TextView.BufferType. For example:

EditText editText = (EditText)findViewById(R.id.edit_text); editText.setText("This sets the text.", TextView.BufferType.EDITABLE); It also inherits TextView's setText(CharSequence) and setText(int) methods, so you can set it just like a regular TextView:

editText.setText("Hello world!"); editText.setText(R.string.hello_world);

  • Related