gpt4 book ai didi

java - 如何从自定义 xml 文件访问 TextView ?

转载 作者:行者123 更新时间:2023-12-02 09:24:52 24 4
gpt4 key购买 nike

我想访问一个名为 user_status 的 TextView ,它位于自定义 xml 布局文件中,以便用一些数据填充它。我想从我的主要 Activity java 类访问它。我该怎么做呢?我已经尝试了一些关于堆栈溢出的答案,但它要么不起作用,要么太过时了。

LayoutInflater inflater = MessageActivity.this.getLayoutInflater();
View inflatedView = inflater.inflate(R.layout.message_row, null);
TextView userMessage= (TextView) inflatedView.findViewById(R.id.user_status);
userMessage.setText("NEW MESSAGE DUMMMY!");

最佳答案

使用

TextView userMessage = inflatedView.findViewById(R.id.user_status);
userMessage.setText("NEW MESSAGE DUMMMY!");

关于java - 如何从自定义 xml 文件访问 TextView ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58407208/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com