我在android中创建了一个小项目,在模拟器上加载我的应用程序后,我按下一个按钮,它只显示一个空白屏幕。我不知道它为什么这样做。欢迎任何帮助。
这是我的主要课程:
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button Button1=(Button)findViewById(R.id.Button1);
Button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(MainActivity.this,ActivityList.class);
startActivity(i);
}}
);
}
}
这是我的 XML 清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sportsfitnessapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity android:name=".ActivityList" />
<activity
android:name="com.example.sportsfitnessapp.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
我真的需要帮助。谢谢。
这是主要的 XML 布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/widget35"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background"
tools:context=".Screen1Activity" >
<TextView
android:id="@+id/Menutxt"
android:layout_width="300dp"
android:layout_height="65dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="#ffffffff"
android:gravity="center"
android:text="@string/Menu"
android:textColor="#ffff0033"
android:textSize="50sp"
android:textStyle="bold|italic"
android:typeface="serif" />
<Button
android:id="@+id/Button1"
android:layout_width="300dp"
android:layout_height="55dp"
android:layout_alignLeft="@+id/Menutxt"
android:layout_below="@+id/Menutxt"
android:layout_marginTop="20dp"
android:gravity="center"
android:text="@string/Choose_Activity"
android:textColor="#ffffffff"
android:textSize="25sp"
android:typeface="serif"
android:onClick="Button1"/>
<Button
android:id="@+id/Button5"
android:layout_width="300dp"
android:layout_height="55dp"
android:layout_alignLeft="@+id/Button1"
android:layout_below="@+id/Button1"
android:gravity="center"
android:text="@string/Graphical_Records"
android:textColor="#ffffffff"
android:textSize="25sp"
android:typeface="serif" />
<Button
android:id="@+id/Button4"
android:layout_width="300dp"
android:layout_height="55dp"
android:layout_alignLeft="@+id/Button5"
android:layout_below="@+id/Button5"
android:gravity="center"
android:text="@string/Training_Schedule"
android:textColor="#ffffffff"
android:textSize="25sp"
android:typeface="serif" />
<Button
android:id="@+id/Button2"
android:layout_width="300dp"
android:layout_height="55dp"
android:layout_alignLeft="@+id/Button4"
android:layout_below="@+id/Button4"
android:gravity="center"
android:text="@string/Weight_Tracker"
android:textColor="#ffffffff"
android:textSize="25sp"
android:typeface="serif" />
<Button
android:id="@+id/Button3"
android:layout_width="300dp"
android:layout_height="55dp"
android:layout_alignLeft="@+id/Button2"
android:layout_below="@+id/Button2"
android:gravity="center"
android:text="@string/Heart_Rate_Monitor"
android:textColor="#ffffffff"
android:textSize="25sp"
android:typeface="serif" />
</RelativeLayout>
这是 ActivityList 类:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class ActivityList extends Activity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
public void onClick(View v) {
Intent i = new Intent();
setContentView(R.layout.activities_list);
startActivity(i);
}
{;
}
}
这是活动列表 XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/widget0"
android:background="@drawable/background" >
<Button
android:id="@+id/Treadmill"
android:layout_width="300dp"
android:layout_height="45dp"
android:layout_alignLeft="@+id/Weights"
android:layout_below="@+id/ActTxt"
android:gravity="center"
android:text="@string/Treadmill"
android:textColor="#ffffffff"
android:textSize="25sp"
android:typeface="serif" />
<Button
android:id="@+id/Aerobics"
android:layout_width="300dp"
android:layout_height="45dp"
android:layout_alignLeft="@+id/Treadmill"
android:layout_below="@+id/Treadmill"
android:gravity="center"
android:text="@string/Aerobic_Steps"
android:textColor="#ffffffff"
android:textSize="25sp"
android:typeface="serif" />
<Button
android:id="@+id/Cycling"
android:layout_width="300dp"
android:layout_height="45dp"
android:layout_alignLeft="@+id/Aerobics"
android:layout_below="@+id/Aerobics"
android:gravity="center"
android:text="@string/Cycling"
android:textColor="#ffffffff"
android:textSize="25sp"
android:typeface="serif" />
<Button
android:id="@+id/Swimming"
android:layout_width="300dp"
android:layout_height="45dp"
android:layout_alignLeft="@+id/Cycling"
android:layout_below="@+id/Cycling"
android:gravity="center"
android:text="@string/Swimming"
android:textColor="#ffffffff"
android:textSize="25sp"
android:typeface="serif" />
<Button
android:id="@+id/Rowing"
android:layout_width="300dp"
android:layout_height="45dp"
android:layout_alignLeft="@+id/Swimming"
android:layout_below="@+id/Swimming"
android:gravity="center"
android:text="@string/Rowing"
android:textColor="#ffffffff"
android:textSize="25sp"
android:typeface="serif" />
<TextView
android:id="@+id/ActTxt"
android:layout_width="300dp"
android:layout_height="55dp"
android:layout_alignLeft="@+id/Treadmill"
android:layout_alignParentTop="true"
android:layout_marginTop="16dp"
android:background="#ffffffff"
android:gravity="center"
android:text="@string/Activities"
android:textColor="#ffff0033"
android:textSize="50sp"
android:typeface="serif" />
<Button
android:id="@+id/ETrainer"
android:layout_width="300dp"
android:layout_height="45dp"
android:layout_alignLeft="@+id/Rowing"
android:layout_below="@+id/Rowing"
android:gravity="center"
android:text="@string/Elliptical_Trainer"
android:textColor="#ffffffff"
android:textSize="25sp"
android:typeface="serif" />
<Button
android:id="@+id/Weights"
android:layout_width="300dp"
android:layout_height="45dp"
android:layout_below="@+id/ETrainer"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="@string/Free_Weights"
android:textColor="#ffffffff"
android:textSize="25sp"
android:typeface="serif" />
</RelativeLayout>