android开发 单击按钮 实现页面间的跳转
2014-04-21 11:27
441 查看
我的MainActivity.java部分代码
public class MainActivity extends ActionBarActivity { //不要定义button类型,会出错 View imageButton1, imageButton2,imageButton3,imageButton4, imageButton5,imageButton6; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (savedInstanceState == null) { getSupportFragmentManager().beginTransaction() .add(R.id.container, new PlaceholderFragment()).commit(); } //根据ID找到界面中的组件按钮 imageButton1=findViewById(R.id.imageButton1); imageButton2=findViewById(R.id.imageButton2); imageButton3=findViewById(R.id.imageButton3); imageButton4=findViewById(R.id.imageButton4); imageButton5=findViewById(R.id.imageButton5); imageButton6=findViewById(R.id.imageButton6); //创建监听器对象 ButtonListener bt = new ButtonListener(); //注册监听 imageButton1.setOnClickListener(bt); imageButton2.setOnClickListener(bt); imageButton3.setOnClickListener(bt); imageButton4.setOnClickListener(bt); imageButton5.setOnClickListener(bt); imageButton6.setOnClickListener(bt); } class ButtonListener implements OnClickListener { //实现单击事件处理方法 @Override public void onClick(View v) { // TODO Auto-generated method stub if(v == imageButton1) { //导航 Intent intent = new Intent(); intent.setClass(MainActivity.this, OtherActivity.class); startActivity(intent); } if(v == imageButton2) { //搜索 Intent intent = new Intent(); intent.setClass(MainActivity.this, OtherActivity.class); startActivity(intent); } if(v == imageButton3) { //地图 Intent intent = new Intent(); intent.setClass(MainActivity.this, OtherActivity.class); startActivity(intent); } if(v == imageButton4) { //周边 Intent intent = new Intent(); intent.setClass(MainActivity.this, OtherActivity.class); startActivity(intent); } if(v == imageButton5) { //推荐 Intent intent = new Intent(); intent.setClass(MainActivity.this, OtherActivity.class); startActivity(intent); } if(v == findViewById(R.id.imageButton6)) { //其他 Intent intent = new Intent(); intent.setClass(MainActivity.this, OtherActivity.class); startActivity(intent); } } }
相关文章推荐
- Android开发 单击按钮实现页面跳转
- 菜鸟 ——android开发,单击按钮之后跳转到另一个页面
- Android开发 第13课 使用Intent实现页面跳转
- 移动开发 - Android - 实现两个页面(Activity)的简单跳转(Intent)
- android仿微信实现欢迎界面、介绍界面及单击按钮跳转到主界面
- Android开发-UI控件:实现登陆页面并跳转和简单的注册页面
- 【Android开发】范例1-实现跟踪鼠标单击状态的图片按钮
- android 点击按钮实现页面跳转并显示以选择信息
- Android开发实现页面的跳转
- Android——单击实现页面跳转(回答小叶子的问题)
- android开发基础:Intent与Bundle的使用,实现页面跳转及信息传递
- 一、东软实践项目2-基于android平台的应用开发:实现页面之间的跳转
- 小KING教你做android项目(二)---实现登陆页面并跳转和简单的注册页面
- android页面跳转的实现
- [Android]Intent 实现页面跳转的方式[转]
- iOS项目开发实战——使用三种方式实现页面跳转与参数传递(二)
- Android页面跳转以及数据传递实现
- Android的按钮单击事件及监听器的实现方式
- Android 实现页面的延时跳转
- 【Android UI设计与开发】2.引导界面(二)使用ViewPager实现欢迎引导页面