我有 3 个 XML 文件。第一个用于主要活动。它有一个按钮。当我触摸此按钮时,它会起作用并将我发送到第二个 XML 文件。第二个屏幕也有一个按钮。现在,我想在这里做同样的操作,我想去第三个 XML 文件。但它不起作用。
我对所有按钮都做了同样的程序。我找不到我的错在哪里。
MainPageActivity
:
public class MainPageActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_page);
ImageButton b1 = (ImageButton) findViewById(R.id.button_compare);
ImageButton b2 = (ImageButton) findViewById(R.id.button_find);
b1.setOnTouchListener(new View.OnTouchListener(){
@Override
public boolean onTouch(View comparePage, MotionEvent event) {
setContentView(R.layout.compare_pagee);
return true;
}
});
b2.setOnTouchListener(new View.OnTouchListener(){
@Override
public boolean onTouch(View findPage, MotionEvent event) {
setContentView(R.layout.find_page);
return true;
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main_page, menu);
return true;
}
}
activity_main_page.xml
:
<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"
tools:context=".MainPageActivity"
android:id="@+id/mainActivity" >
<ImageButton
android:id="@+id/button_compare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="false"
android:layout_alignParentTop="false"
android:adjustViewBounds="true"
android:scaleType="center"
android:src="@drawable/compare"
/>
<ImageButton
android:id="@+id/button_find"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="69dp"
android:adjustViewBounds="true"
android:src="@drawable/find"
/>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center_vertical|center_horizontal"
android:text="Tap the top to Compare!"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/button_compare"
android:gravity="center_vertical|center_horizontal"
android:text="Tap the bottom to Find!"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
Compare
:
public class Compare extends Activity{
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.compare_pagee);
ImageButton b3 = (ImageButton) findViewById(R.id.compareButton);
b3.setOnTouchListener(new View.OnTouchListener(){
@Override
public boolean onTouch(View comparePage, MotionEvent event) {
setContentView(R.layout.compare_pagee);
return true;
}
});
}
}
compare_pagee.xml
:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:background="@drawable/backgroundwallpaper"
android:clickable="true"
android:orientation="vertical"
tools:context=".Compare" >
<Spinner
android:id="@+id/spinner2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Spinner
android:id="@+id/spinner3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Spinner
android:id="@+id/spinner5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<ImageButton
android:id="@+id/compareButton"
android:layout_width="139dp"
android:layout_height="74dp"
android:src="@drawable/comparebutton" />
<Spinner
android:id="@+id/spinner6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Spinner
android:id="@+id/spinner4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Spinner
android:id="@+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>