我想要去我的應用程序的下一個活動,但onClick無法進入下一個活動。這是我迄今爲止嘗試過的代碼。 onClick播放我剛剛添加的聲音。在它工作正常之前。onClick()不會去下一個活動
public class MainActivity extends Activity {
ImageButton imageButton;
Animation performAnimation1;
ImageView androidImageView;
MediaPlayer mp;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButton();
performAnimation1 = AnimationUtils.loadAnimation(this, R.layout.animation1);
performAnimation1.setRepeatCount(4);
androidImageView = (ImageView)findViewById(R.id.androidImageView);
androidImageView.startAnimation(performAnimation1);
mp = MediaPlayer.create(this, R.raw.click);
imageButton = (ImageButton)this.findViewById(R.id.button1);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mp.start();
}
});
}
public void addListenerOnButton() {
imageButton = (ImageButton) findViewById(R.id.button1);
imageButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(MainActivity.this, Numbers.class);
startActivity(intent);
}
});
}
}
Mainfest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.learning_numbers"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="1"
android:targetSdkVersion="18" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:theme="@style/AppTheme" >
<activity
android:name="com.android.learning_numbers.MainActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Numbers"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />
</application>
</manifest>