如何使一个按钮切换到一个新的活动? [英] How do I make a button switch to a new activity?
本文介绍了如何使一个按钮切换到一个新的活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想开始使用一个按钮,一个新的活动,但新的活动只显示约五秒钟,回来。这是我的code样子:
公共类飞溅扩展活动实现OnClickListener {
按钮旁边,previous,菜单;
ViewFlipper VF;@覆盖
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.splash); 接下来=(按钮)findViewById(R.id.Button01);
菜单=(按钮)findViewById(R.id.menu);
previous =(按钮)findViewById(R.id.Button02);
VF =(ViewFlipper)findViewById(R.id.ViewFlipper1); next.setOnClickListener((OnClickListener)本);
previous.setOnClickListener((OnClickListener)本); menu.setOnClickListener(新View.OnClickListener(){
公共无效的onClick(视图v){
意向意图=新意图(Splash.this,Menu.class);
startActivity(意向);
}
});
} 公共无效的onClick(视图v){
// TODO自动生成方法存根
如果(V == NEXT){
vf.showNext();
}
如果(V == previous){
vf.show previous();
}
}
}
这是code的菜单活动。这是不完整的,虽然:
公共类菜单扩展宣誓实现OnClickListener {
按钮有关;
按钮接触;
按钮的产品;
按钮卡;// @覆盖
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.menu); 关于=(按钮)findViewById(R.id.button1);
接触=(按钮)findViewById(R.id.button2);
产品=(按钮)findViewById(R.id.button3);
卡=(按钮)findViewById(R.id.button4);}
@覆盖
公共无效的onClick(查看为arg0){
// TODO自动生成方法存根}
}
解决方案
具有u声明新的活动在你的manifest.xml。
你必须在这两者之间写这....<应用> ........
<活动机器人:菜单名称=
机器人:标签=XYZ/>
< /用途>
I am trying to start a new activity using a button, but the new activity only shows for about five seconds and comes back. This is what my code looks like:
public class Splash extends Activity implements OnClickListener{
Button next, Previous, menu;
ViewFlipper vf;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
next = (Button)findViewById(R.id.Button01);
menu = (Button)findViewById(R.id.menu);
Previous = (Button)findViewById(R.id.Button02);
vf = (ViewFlipper)findViewById(R.id.ViewFlipper1);
next.setOnClickListener((OnClickListener) this);
Previous.setOnClickListener((OnClickListener) this);
menu.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(Splash.this, Menu.class);
startActivity(intent);
}
});
}
public void onClick(View v) {
// TODO Auto-generated method stub
if(v==next){
vf.showNext();
}
if(v==Previous){
vf.showPrevious();
}
}
}
This is the code for the Menu activity. It's incomplete, though:
public class Menu extends AFFIRMATION implements OnClickListener{
Button about;
Button contact;
Button products;
Button cards;
//@override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
about = (Button)findViewById(R.id.button1);
contact = (Button)findViewById(R.id.button2);
products = (Button)findViewById(R.id.button3);
cards = (Button)findViewById(R.id.button4);
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
}
}
解决方案
have u Declare the new Activity in your manifest.xml.
you have to write this in between....
<application> ........
<activity android:name=".Menu"
android:label="xyz"/>
</application>
这篇关于如何使一个按钮切换到一个新的活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文