如何调用findViewWithTag在活动的onCreate()方法? [英] How do I call findViewWithTag in the OnCreate() method of an activity?

查看:145
本文介绍了如何调用findViewWithTag在活动的onCreate()方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到一个错误,当我称之为 findViewWithTag()的onCreate()

I get an error when I call findViewWithTag() in the onCreate()

的方法 findViewWithTag(字符串)是未定义的类型
  MainActivity

"The method findViewWithTag(String) is undefined for the type MainActivity"

有没有什么别的选择吗?

Is there any alternative?

推荐答案

findViewWithTag()只为一个视图定义。

findViewWithTag() is only defined for a View.

如果你有活动的内容查看您使用设置的setContentView(内容查看),你可以使用一个参考 contentView.findViewWithTag()

If you have a reference to the contentView of the activity that you set with setContentView(contentView), you can use contentView.findViewWithTag().

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

If you don't have a reference to that view, you can also use findViewById(R.id.your_content_view_id).findViewWithTag(tag).

这篇关于如何调用findViewWithTag在活动的onCreate()方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆