Android 是否从MainAcivity.java以不同的布局xml更新textview?
我在布局文件夹game.xml中创建了一个新的.xml文件。它包含一个文本视图 是否可以从我的主要活动中设置game.xml中的textview上的文本 game.xml(文本视图部分)Android 是否从MainAcivity.java以不同的布局xml更新textview?,android,android-layout,android-emulator,android-widget,textview,Android,Android Layout,Android Emulator,Android Widget,Textview,我在布局文件夹game.xml中创建了一个新的.xml文件。它包含一个文本视图 是否可以从我的主要活动中设置game.xml中的textview上的文本 game.xml(文本视图部分) 我这样试过了。但它不起作用。有谁能帮我吗?您不能在此处设置视图,TextView,该视图不是通过充气器或setContentView()充气布局创建的。您可以通过Intent将值传递给实际使用TextView Intent intent = new Intent(MainActivity.this, NextA
我这样试过了。但它不起作用。有谁能帮我吗?您不能在此处设置视图,
TextView
,该视图不是通过充气器或setContentView()
充气布局创建的。您可以通过Intent
将值传递给实际使用TextView
Intent intent = new Intent(MainActivity.this, NextActivity.class);
intent.putExtra("key", actualword);
startActivity(intent);
其中NextActivity
是将显示文本视图的活动
然后您可以获取该值并在其他活动中设置它
Intent recIntent = getIntent();
String text = recIntent.getStringExtra("key");
TextView textView1 = (TextView) findViewById(R.id.tV1); //get a reference to the textview on the game.xml file.
textView1.setText(text);
使用setContentView(R.layout.game)后第二个活动的onCreate()
中的code>,简短回答,否
布局文件只是一个蓝图。直到布局膨胀(变成视图),实际的文本视图才存在
我的问题是,(如何)您没有使用这个game.xml吗?是在另一个活动中吗
Intent intent = new Intent(MainActivity.this, NextActivity.class);
intent.putExtra("key", actualword);
startActivity(intent);
Intent recIntent = getIntent();
String text = recIntent.getStringExtra("key");
TextView textView1 = (TextView) findViewById(R.id.tV1); //get a reference to the textview on the game.xml file.
textView1.setText(text);