0
First_layout.xml兩個XML文件,但在第一個活動訪問第二XML控制
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout2" android:layout_width="match_parent"
android:layout_height="match_parent" android:orientation="vertical">
<TextView android:id="@+id/tactiveDateDisplay"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="TextView" />
</LinearLayout>
Second_layout.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout2" android:layout_width="match_parent"
android:layout_height="match_parent" android:orientation="vertical">
<TextView android:id="@+id/tactiveDateDisplay1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="TextView" />
</RelativeLayout>
MainActivity.java
public class MainActivity extends Activity
{
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv=(TextView)findViewById(R.layout.activity_main);
call();
}
private void call()
{
setContentView(R.layout.seccond);//second xml file
//At this line i want to access the second layout textview control
}
}
這是我的代碼,所以如何訪問MainActvity.java文件中的second_layout.xml文件控件TextView
K我也加了代碼 – Andrio