当我在 onCreate()
中调用 findViewWithTag()
时出现错误
"The method
findViewWithTag(String)
is undefined for the type MainActivity"
还有其他选择吗?
最佳答案
findViewWithTag()
仅为 View 定义。
如果您有对使用 setContentView(contentView)
设置的 Activity 的 contentView 的引用,则可以使用 contentView.findViewWithTag()
。
如果您没有对该 View 的引用,您也可以使用 findViewById(R.id.your_content_view_id).findViewWithTag(tag)
。
关于android - 如何在 Activity 的 OnCreate() 方法中调用 findViewWithTag?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12545253/