我在我的佈局文件夾中創建了一個名爲game.xml的新.xml文件。它包含一個TextView。從MainAcivity.java更新不同佈局xml中的textview?
是否可以在我的主要活動中設置位於game.xml中的textview上的文本?
game.xml(TextView的部分)
<TextView
android:id="@+id/tV1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/imageView1"
android:layout_centerVertical="true"
android:text="TextView" />
MainActivity.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setImageArray();
String actualword = chooseWord(words);
createLetterArray(actualword);
TextView textView1 = (TextView) findViewById(R.id.tV1); //get a reference to the textview on the game.xml file.
textView1.setText(actualword);
}
...
我嘗試了這種方式。但它不起作用。任何人都可以幫助我?