2013-07-22 26 views
0

中嘗試鏈接兩個xml頁面activity_main和activity_addbaby時,無法鏈接兩個xml頁面。我在activity_main一個按鈕,當我點擊我應該就可以切換到另一個XML,但模擬器犯規顯示在XML中的UI元素的其他XML文件在Android開發(SDK)

我的代碼是這樣

主要活動 公衆類MainActivity延伸活動{

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    setContentView(R.layout.activity_main); 

    final Button button = (Button) findViewById(R.id.button1); 
    button.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View V) 
     { 
      Intent i = new Intent(MainActivity.this, Addbaby.class); 
       startActivity(i); 
     } 
    }); 

和Addbaby.class就像 公共類Addbaby延伸活動 {

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_addbaby); 

}

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context=".MainActivity" > 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/hello_world" /> 

<Button 
    android:id="@+id/button1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/textView1" 
    android:layout_marginLeft="17dp" 
    android:layout_marginTop="68dp" 
    android:layout_toRightOf="@+id/textView1" 
    android:text="New Profile" /> 

<Button 
    android:id="@+id/button2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignRight="@+id/button1" 
    android:layout_centerVertical="true" 
    android:text="Existing Profile" /> 

</RelativeLayout> 

我的鏈接的XML文件是

<EditText 
    android:id="@+id/editText1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentTop="true" 
    android:layout_marginRight="92dp" 
    android:layout_marginTop="58dp" 
    android:ems="10" > 

    <requestFocus /> 
    </EditText> 

    <TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/editText1" 
    android:layout_alignParentTop="true" 
    android:layout_marginLeft="14dp" 
    android:layout_marginTop="26dp" 
    android:text="Name" /> 

    <TextView 
    android:id="@+id/textView2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/datePicker1" 
    android:layout_below="@+id/editText1" 
    android:layout_marginTop="34dp" 
    android:text="DOB" /> 

    <TextView 
    android:id="@+id/textView3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="47dp" 
    android:text="email" /> 

    <EditText 
    android:id="@+id/editText2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/textView3" 
    android:layout_below="@+id/textView3" 
    android:layout_marginTop="17dp" 
    android:ems="10" 
    android:inputType="textEmailAddress" /> 

    <Button 
    android:id="@+id/add_Baby_dob" 
    android:layout_width="200.0dip" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/textView2" 
    android:layout_marginTop="36dp" 
    android:layout_toRightOf="@+id/textView2" /> 

    </RelativeLayout> 

回答

0

我認爲這是不希望看到的事情的好辦法,你從一個切換到另一個活動,而不是從XML文件另一個。 但是,它會起作用。你應該發佈佈局文件,這個問題可能來自xml代碼。

+0

我在你說的方法做就OK奉上我的佈局文件以及他們在這裏,他們是 – Sri

0

我認爲這是在第二佈局相對佈局的不正確的定義,並保持android:context=.className中相對佈局的定義

+0

我的xml文件就像 – Sri

+0

沒有朋友它沒有爲我工作 – Sri