在Android应用程序中使用意图展现另一个活动 [英] Using Intent in an Android application to show another activity
问题描述
在我的Android应用程序,我有两个活动课。我对第一个按钮,我想说明的第二个被点击时,但我得到一个错误。下面是类:
In my Android application, I have two activity classes. I have a button on the first one and I want to show the second when it is clicked, but I get an error. Here are the classes:
public class FirstActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button orderButton = (Button)findViewById(R.id.order);
orderButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(FirstActivity.this, OrderScreen.class);
startActivity(intent);
}
});
}
}
这应显示被点击的按钮,但从来不会第二类:
The second class that should show when the button is clicked, but never does:
public class OrderScreen extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.order);
Button orderButton = (Button) findViewById(R.id.end);
orderButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
}
}
如何创建一个按钮,将显示第二个活动?
How do I create a button that will show the second activity?
推荐答案
这个问题是在 OrderScreen 活动
未添加到<一个href="http://developer.android.com/guide/topics/manifest/manifest-intro.html">AndroidManifest.xml.有一次,我补充说,作为一个应用程序的节点,它的工作正常。
The issue was the OrderScreen Activity
wasn't added to the AndroidManifest.xml. Once I added that as an application node, it worked properly.
<activity android:name=".OrderScreen" />
这篇关于在Android应用程序中使用意图展现另一个活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!