简体   繁体   English

如何解决 kotlin 中的 findviewbyid?

[英]how to resolve findviewbyid in kotlin?

I tried almost everything but it doesn't seem to work, I keep getting a cannot resolve findviewById for the buttons at the bottom.我几乎尝试了所有方法,但它似乎不起作用,我不断收到无法解析底部按钮的 findviewById。 the button declarations have the same errors but I have fixed those correctly, the bottom buttons don't seem to behave the same way.按钮声明具有相同的错误,但我已正确修复这些错误,底部按钮的行为似乎不同。 I'm new to android, please help!我是 android 的新手,请帮忙!

1

add requireActivity() before findViewById.在 findViewById 之前添加requireActivity() for example:例如:

btn = requireActivity().findViewById<Button>(R.id.btn)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM