本文介绍了Android - 如何通过单击按钮打开 Activity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过单击按钮(ButStart)打开 Activity(GameProcess)?

How do I open an Activity(GameProcess) by clicking on a button(ButStart)?

我已经对其进行了编辑并加以体现.你看到了什么错误?当我点击按钮(ButStart)时它崩溃了.

I already edited it and take to manifest. What mistakes do you see? It crashes when I tap the button(ButStart).

package com.makeandroid.klikomania;

public class KlikomaniaActivity extends Activity {

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

    final Button Butstart = (Button)findViewById(R.id.butstart);
    final Button Butrez = (Button)findViewById(R.id.butrez);

    Butstart.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent intent = new Intent(KlikomaniaActivity.this,GameProcess.class);
             startActivity(intent);
        }
    });
}

}

这是 GameProgress 活动:

And Here is GameProgress Activity:

package com.makeandroid.klikomania;


public class GameProcess extends Activity {



 @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.gameprocess);

        }
 }

清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.makeandroid.klikomania"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="16" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity android:name="com.makeandroid.klikomania.GameProcess"></activity>
    <activity
        android:name="com.makeandroid.klikomania.KlikomaniaActivity"
        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>

推荐答案

可能你的 button Butstartnull.检查 main.xml

Probably your button Butstart is null. Check "butstart" id in your main.xml

这篇关于Android - 如何通过单击按钮打开 Activity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-02 12:16