我想将值“It is work”赋给www.example.com中的textviewMainActivity.java;(textview在other.xml中,而不是activity_main. xml中)正如您所看到的,我是使用setText完成此操作的;但是当我运行应用程序并在主Activity(activity_main.xml)中触摸按钮运行other.xml层时,它的文本视图没有转换为“It is work”谢谢你的帮助x1c 0d1x '公共类MainActivity扩展了AppCompatActivity { ActivityMainBinding activityMainBinding;其他绑定其他绑定;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
activityMainBinding = ActivityMainBinding.inflate(getLayoutInflater());
otherBinding = OtherBinding.inflate(getLayoutInflater());
setContentView(activityMainBinding.getRoot());
otherBinding.textview.setText("It is Work");
activityMainBinding.button.setOnClickListener(view1 -> {
setContentView(R.layout.other);
});
}
'
1条答案
按热度按时间zbq4xfa01#
我写了一些代码,并给予了问题的解释