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

Eni*_*man 3 android

我得到一个错误,当我打电话findViewWithTag()onCreate()

" findViewWithTag(String)对于MainActivity类型,该方法未定义"

还有其他选择吗?

Vin*_*noy 9

findViewWithTag() 仅为视图定义.

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

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

  • 半正确,方法确实是[`findViewWithTag()`](http://developer.android.com/reference/android/view/View.html#findViewWithTag%28java.lang.Object%29),但它是View的一部分不是Activity类. (2认同)