嗨,我想问一下为什么我的按钮在单击时不起作用我只是复制了其他有效的布局按钮代码并尝试自己创建它但仍然不起作用?
这是我的代码
.java 包 com.thesis.logicic;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
public class Menu extends Activity
{
Button beginner;
@Override
protected void onCreate(Bundle MenuButtons) {
super.onCreate(MenuButtons);
}
public void onClick(View v)
{
Button clickedButton = (Button) v;
switch (clickedButton.getId())
{
case R.id.btnBeginner:
setContentView(R.layout.gameplay);
break;
case R.id.btnLearner:
setContentView(R.layout.menu);
break;
}
}
}
.xml
<ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/categories" >
<Button
android:id="@+id/btnLearner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btnBeginner"
android:layout_centerHorizontal="true"
android:background="@drawable/learner_menu" />
<Button
android:id="@+id/btnBeginner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/btnLearner"
android:layout_alignParentTop="true"
android:background="@drawable/beginner_menu" />
</RelativeLayout>
</ScrollView>
</LinearLayout>
和清单
<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=".Splash"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ThesisActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.thesis.logipic.THESISACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".logipic.Menu"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.thesis.logipic.MENU" />
<category android:name="android.intent.category.ALTERNATIVE" />
</intent-filter>
</activity>
<activity
android:name=".Gameplay"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.thesis.logipic.GAMEPLAY" />
<category android:name="android.intent.category.ALTERNATIVE" />
</intent-filter>
</activity>
<activity
android:name=".Beginner"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.thesis.logipic.BEGINNER" />
<category android:name="android.intent.category.ALTERNATIVE" />
</intent-filter>
</activity>
</application>
</manifest>