我是 kotlin 和 android 的新手,我剛剛開始使用視圖系結。我試圖制作這個位置應用程式,并在通過 datepickerdialog 設定日期時,當我嘗試使用系結編輯 textview 的文本時,它給了我錯誤。有人能幫我嗎?
私人樂趣 displaySelectedDate(timestamp : Long){
binding?.etDate?.text = format.format(timestamp)
uj5u.com熱心網友回復:
將其更改為
binding?.etDate?.setText(format.format(timestamp))
uj5u.com熱心網友回復:
如果你查看 EditText 的檔案,你會發現一個 setText() 方法。它接受一個字串和一個 TextView.BufferType。例如:
EditText editText = (EditText)findViewById(R.id.edit_text); editText.setText("這會設定文本。", TextView.BufferType.EDITABLE); 它還繼承了 TextView 的 setText(CharSequence) 和 setText(int) 方法,因此您可以像常規 TextView 一樣設定它:
editText.setText("你好世界!"); editText.setText(R.string.hello_world);
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/517396.html
上一篇:查找兩列的每個組合的MAX值
