【问题标题】:Get view created using inflater.inflate获取使用 inflater.inflate 创建的视图
【发布时间】:2020-11-25 16:25:23
【问题描述】:

我不明白这一点。我无法在使用 inflater.inflate() 创建的视图上设置文本()

val justView = inflater.inflate(R.layout.mybutton, null, false)
ayatList.addView(justView)
justView.setText("OK")

【问题讨论】:

  • 显示布局文件,mybutton ?
  • 能否请您添加您遇到的错误?

标签: android android-layout android-fragments


【解决方案1】:

您需要将结果转换为TextView(假设该布局只是TextView——注意ButtonTextView 的一种类型):

val justView = inflater.inflate(R.layout.mybutton, null, false) as TextView
ayatList.addView(justView)
justView.setText("OK")

【讨论】:

  • @Habibi 我注意到你不接受我的回答:有问题吗?
猜你喜欢
  • 2021-04-22
  • 2012-03-16
  • 1970-01-01
  • 2012-12-12
  • 2023-04-08
  • 2011-07-31
  • 2014-05-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多