如何在活动的OnCreate()方法中调用findViewWithTag?

时间:2012-09-22 15:48:09

标签: android

我在findViewWithTag()

中拨打onCreate()时收到错误消息
  

“方法findViewWithTag(String)未定义类型   MainActivity“

还有其他选择吗?

1 个答案:

答案 0 :(得分:9)

findViewWithTag()仅为视图定义。

如果您引用了使用setContentView(contentView)设置的活动的contentView,则可以使用contentView.findViewWithTag()

如果您没有对该视图的引用,也可以使用findViewById(R.id.your_content_view_id).findViewWithTag(tag)