我想访问一个名为 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/