這似乎是一個簡單的功能,但我已經閱讀和審查了無數的教程,並嘗試多次,以使其發揮作用,我仍然沒有成功。如何在點擊後激活一個按鈕切換到另一個佈局?
我有標題爲「主」開幕XML頁面 我有第二個XML頁面標題爲「菜單」 我有標題爲「ButtontestingActivity.java」 一號java的活動我都第二個java活動名爲「菜單」
在ButtontestingActivity.java我有...
package com.package2.Buttontesting;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class ButtontestingActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button Button1 = (Button) findViewById(R.id.sweetness);
Button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(new Intent("com.package2.Buttontesting.MENU"));
}
});
}
@Override
protected void onPause() {
super.onPause();
}
}
main.xml中我有...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/splash"
android:orientation="vertical" >
<Button
android:id="@+id/sweetness"
android:layout_width="40dp"
android:layout_height="78dp"
android:layout_marginLeft="52dp"
android:layout_marginTop="40dp"
android:visibility="visible"
/>
</LinearLayout>
在清單我...
<application
android:icon="@drawable/face"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".ButtontestingActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:label="@string/app_name"
android:name=".Menu" >
<intent-filter >
<action android:name="com.package2.Buttontesting.MENU" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
,我有機器人:背景=「@繪製/菜單」以我menu.xml文件
當我安裝的應用程序在我的AVD第一佈局顯示但是當我按下按鈕打開第二個佈局時,AVD發送消息
「應用程序Buttontesting(process com.package2.Buttontesting)已意外停止。請重試」
,然後我返回到應用程序菜單。
請添加您在logcat中越來越錯誤信息,它可以幫助在得到準確的答案。 – kosa 2011-12-26 17:24:44