Android 按钮不存在';不去新的一页吗?
我创建了一个按钮,我希望它在点击时转到另一个页面。我认为我做的一切都是对的,但是当我在emulator中运行项目时,按钮没有做任何事情,它给我一个错误,项目已经停止工作,应用程序停止在emulator上工作。还有想法 下面是按钮的xmlAndroid 按钮不存在';不去新的一页吗?,android,eclipse,Android,Eclipse,我创建了一个按钮,我希望它在点击时转到另一个页面。我认为我做的一切都是对的,但是当我在emulator中运行项目时,按钮没有做任何事情,它给我一个错误,项目已经停止工作,应用程序停止在emulator上工作。还有想法 下面是按钮的xml <Button android:id="@+id/button1" android:layout_width="300dp" android:layout_height="wrap_content" android:layo
<Button
android:id="@+id/button1"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textStyle="bold"
android:hint="@string/Play_Button" />
package com.dakota.amnesiadino;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button play_button = (Button) findViewById(R.id.button1);
play_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.dakota.amnesiadino.play_button"));
}
});
}
}
<activity
android:name="com.dakota.amnesiadino.levels_home"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.play_button" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
这是按钮的清单
<Button
android:id="@+id/button1"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textStyle="bold"
android:hint="@string/Play_Button" />
package com.dakota.amnesiadino;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button play_button = (Button) findViewById(R.id.button1);
play_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.dakota.amnesiadino.play_button"));
}
});
}
}
<activity
android:name="com.dakota.amnesiadino.levels_home"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.play_button" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
首先,当你说“没有进入下一页”时,要更具体一些 这个页面是一个屏幕??活动是否由xml文件定义?是一个网址吗?? 你的问题打得不太清楚 据我所知, 也许,你应该在OnClick正文中写下这样的内容
Intent intent = new Intent(getApplicationContext(),levels_home.class);
startActivity(intent);
如果您有一个xml文件和一个用于新活动的相应的.java文件,这个解决方案就可以工作 最好的方法是:
Intent intent = new Intent(getApplicationContext(),levels_home.class);
startActivity(intent);
以及设置清单:
<activity
android:name="com.dakota.amnesiadino.levels_home"
android:label="@string/app_name" >
在您的清单中,LAUNCHER可能存在复制和粘贴错误,默认为:
<intent-filter>
<action android:name="android.intent.action.play_button" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>