我的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开发 单击按钮 实现页面间的跳转的更多相关文章

  1. React Native移动开发实战-3-实现页面间的数据传递

    React Native使用props来实现页面间数据传递和通信.在React Native中,有两种方式可以存储和传递数据:props(属性)以及state(状态),其中: props通常是在父组件 ...

  2. Android开发中按钮的语法

    按钮的主要作用就是触发一个动作,所以会用到监听器. 如何为按钮添加单机事件监听器: 1.匿名内部类作为单机事件监听器 案例: 首先在.xml文件中添加一个按钮一,然后设置其id属性,然后在main里获 ...

  3. Android实现不同Active页面间的跳转

    Intent intent = new Intent(); intent.setClass(ErrorPageActive.this, LoginActive.class); startActivit ...

  4. web开发模式小结:页面乱码和跳转

    本文由付老师总结书写 java开发模式: (1)第一种开始模式:javaBean+jsp : 优点:可以为web程序在jsp中减少java代码量 适用于该开发模式的jsp的动作元素:<jsp:u ...

  5. Html学习之一(锚点链接的使用,页面间的跳转)

    页面一: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <ti ...

  6. 【HarmonyOS】【DevEco Studio】NOTE04:How to Jump to a Page(页面间的跳转)

    页面创建与基本设置 创建页面 创建两个新页面,分别为AbilityPage1.AbilityPage2 设置页面基本内容 以AbilityPage1为例 导包 import com.example.m ...

  7. MUI+html5+script 不同页面间转跳(九宫格)

    在点击图片/标题需要跳转到详情页面的使用场景中,首先定义图片元素的id为"tyzc",是同一类下的第一个图片 <img src="img/img3.png" ...

  8. 开发 | 如何在微信小程序的页面间传递数据?

    我们在之前发布过小程序页面传值方法的简单介绍,说明了在小程序开发中,两种常见的页面之间传值方法. 本期,知晓程序(微信号 zxcx0101)为你带来的是「倒数记日」小程序开发者带来的,小程序开发中,有 ...

  9. Metro 页面间跳转报错、打包和安装一个本地的Metro类型应用

    1.模板页面间传值跳转报错误 参照:http://www.cnblogs.com/dagehaoshuang/archive/2012/08/31/2665166.html#2862480 强烈推荐, ...

随机推荐

  1. 避免SWF被内存提取工具提取的方法

    内存工具从内存中抓取SWF一般是依靠寻找SWF的前7个字节(3个SWF文件必有的标示字节“FWS”或“CWS”或“ZWS”+4个记录该SWF文件长度的字节),所以避免被提取我们只要在加载SWF到内存后 ...

  2. 【转】linux下cppunit的安装

    以下内容来自:http://www.51testing.com/html/51/279751-170160.html 1. 安装 cppunit的下载地址为:http://sourceforge.ne ...

  3. Codeforces Round #325 (Div. 2) F. Lizard Era: Beginning meet in the mid

    F. Lizard Era: Beginning Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...

  4. Effective C++ 第二版 17)operator=检查自己 18)接口完整 19)成员和友元函数

    条款17 在operator=中检查给自己赋值的情况 1 2 3 class  X { ... }; X a; a = a;  // a 赋值给自己 >赋值给自己make no sense, 但 ...

  5. 开源企业IM,免费企业即时通讯软件-ENTBOOST云通讯平台Windows(r174)版本号公布

    经过恩布团队全体成员的不懈努力,依照原定计划,最终在今天(5月14日)公布第二个开源版本号,恩布企业互联IM,ENTBOOST 0.2.0(r174beta)Windows版本号:主要功能支持文本.表 ...

  6. iOS开发——新特性OC篇&IOS9 系统新特性

    IOS9 系统新特性 2015年6月89号凌晨召开的WWDC 2015苹果开发者大会发布了全新的iOS 9系统,PC6小编今天给大家整理了这次iOS9的系统更新带来了哪些新的功能与升级,本次新功能一览 ...

  7. 【Android动画】之Tween动画 (渐变、缩放、位移、旋转)

    Android 平台提供了两类动画. 一类是Tween动画,就是对场景里的对象不断的进行图像变化来产生动画效果(旋转.平移.放缩和渐变). 第二类就是 Frame动画,即顺序的播放事先做好的图像,与g ...

  8. Ruby简介,附带示例程序

    Ruby语言是日本人松本行弘于1993年器开始着手研发,经历2年时间,发布了Ruby语言的第一个版本:0.95版.     Ruby是一种非常简介的解释性语言,一种纯粹的面向对象编程语言,甚至比Jav ...

  9. mysqldump 的一些使用参数

    备份数据库#mysqldump 数据库名 >数据库备份名 #mysqldump -A -u用户名 -p密码 数据库名>数据库备份名 #mysqldump -d -A --add-drop- ...

  10. MATLAB的循环结构

    循环结构有两种基本形式:while 循环和for 循环.两者之间的最大不同在于代码的重复是如何控制的.在while 循环中,代码的重复的次数是不能确定的,只要满足用户定义的条件,重复就进行下去.相对地 ...