我想要獲得一個簡單的按鈕來在屏幕之間進行導航,我真的不確定我做了什麼錯誤,因爲我遵循了指南!爲什麼我的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 {
Button aButton;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
} {
aButton = (Button) this.findViewById(R.id.scales);
aButton.setOnClickListener({;new OnClickListener();
}
public void onClick(View v){
Intent i = new Intent(mainactivity.this, buttons2.class); startActivity(i);
} }
清單:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.xx"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.xx.MainActivity"
android:label="@string/app_name" >
android:label="MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="Buttons2" android:label="Buttons2"></activity>
</application>
</manifest>
代碼第二頁:
import android.app.Activity;
import android.os.Bundle;
public class Buttons2 extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.other);
} }
請幫幫忙!
謝謝!
嘗試刪除;在新的aButton.setOnClickListener({; new OnClickListener(); - > aButton.setOnClickListener({new OnClickListener(); – 2013-04-30 12:02:42