main.xml 中定义的 TextView - 如何“命名”它能够使用 - setText() 方法吗?

发布于 2024-09-02 12:29:10 字数 332 浏览 2 评论 0原文

我正在探索android和开发,我发现了一个问题。

我的应用程序 UI 在 main.xml 中定义,

我定义了 2 个文本和 2 个按钮 - 简单的应用程序。

我读到我可以使用 setText() 方法更改 ACTIVITY 中的文本。

这就是问题 - 我如何指向 setText() 方法?我如何告诉它更改指定的文本?

如果我使用 NEW TextView NAME 对象在 Activity 中声明 TextView,我只需要使用 NAME.setText(STRING)...但我没有,所以我没有像对象的 NAME 之类的东西?

这怎么能做到呢?

I am exploring android and developement and I found one problem.

My app UI is defined in main.xml

I have 2 texts and 2 buttons defined - easy app.

I read that I may be able to change TEXT in the ACTIVITY using the setText() method.

And thats the problem - how do I POINT the setText() Method? How do I tell it to change a specified text?

If I would declare the TextView inside the Activity with NEW TextView NAME Object, I would just need to use NAME.setText(STRING)... But I didnt so i dont have anything like NAME of the object?

How can this be done?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

知你几分 2024-09-09 12:29:10

您不需要定义一个新的 TextView。你需要这段代码:

TextView textView = (TextView) findViewById(R.id.name_of_your_textview);
textView.setText("bla bla bla");

You don't need do define a new TextView. You need this code:

TextView textView = (TextView) findViewById(R.id.name_of_your_textview);
textView.setText("bla bla bla");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文