我用文本视图创建了一个片段,但每次运行代码时,我都会收到一条错误消息,提示“tipAmount 属性未初始化”。我似乎无法弄清楚出了什么问题。这是代码:
class ShowTipFragment : Fragment() {
private lateinit var tipAmount : TextView
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
// Inflate the layout for this fragment
val view = inflater.inflate(R.layout.fragment_show_tip, container, false)
tipAmount = view.findViewById(R.id.tip_amount)
tipAmount.setText("")
return view
}
fun updateTextView (tip : String) {
val tipText = "You should definitely tip $tip"
tipAmount.setText(tipText)
}
}