android开发 单击按钮 实现页面间的跳转
我的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开发 单击按钮 实现页面间的跳转的更多相关文章
- React Native移动开发实战-3-实现页面间的数据传递
React Native使用props来实现页面间数据传递和通信.在React Native中,有两种方式可以存储和传递数据:props(属性)以及state(状态),其中: props通常是在父组件 ...
- Android开发中按钮的语法
按钮的主要作用就是触发一个动作,所以会用到监听器. 如何为按钮添加单机事件监听器: 1.匿名内部类作为单机事件监听器 案例: 首先在.xml文件中添加一个按钮一,然后设置其id属性,然后在main里获 ...
- Android实现不同Active页面间的跳转
Intent intent = new Intent(); intent.setClass(ErrorPageActive.this, LoginActive.class); startActivit ...
- web开发模式小结:页面乱码和跳转
本文由付老师总结书写 java开发模式: (1)第一种开始模式:javaBean+jsp : 优点:可以为web程序在jsp中减少java代码量 适用于该开发模式的jsp的动作元素:<jsp:u ...
- Html学习之一(锚点链接的使用,页面间的跳转)
页面一: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <ti ...
- 【HarmonyOS】【DevEco Studio】NOTE04:How to Jump to a Page(页面间的跳转)
页面创建与基本设置 创建页面 创建两个新页面,分别为AbilityPage1.AbilityPage2 设置页面基本内容 以AbilityPage1为例 导包 import com.example.m ...
- MUI+html5+script 不同页面间转跳(九宫格)
在点击图片/标题需要跳转到详情页面的使用场景中,首先定义图片元素的id为"tyzc",是同一类下的第一个图片 <img src="img/img3.png" ...
- 开发 | 如何在微信小程序的页面间传递数据?
我们在之前发布过小程序页面传值方法的简单介绍,说明了在小程序开发中,两种常见的页面之间传值方法. 本期,知晓程序(微信号 zxcx0101)为你带来的是「倒数记日」小程序开发者带来的,小程序开发中,有 ...
- Metro 页面间跳转报错、打包和安装一个本地的Metro类型应用
1.模板页面间传值跳转报错误 参照:http://www.cnblogs.com/dagehaoshuang/archive/2012/08/31/2665166.html#2862480 强烈推荐, ...
随机推荐
- 第1组UI组件:布局管理器
1 布局管理的来源 为了让UI在不同的手机屏幕上都能运行良好----不同手机屏幕的分辨率/尺寸并不完全相同,如果让程序手动控制每个组件的大小.位置,会给编程带来巨大的麻烦.为了解决这个问题.andro ...
- 常用 Unicode 符号列表
Unicode 中包含了各种符号,我们可以作为图标来使用.这里整理一下常用的一些符号. 一.拉丁字母补全(Latin-1 Supplement):U+0080 至 U+00FF Unicode 编号 ...
- XMPP——Smack[1]连接、登陆及账户操作
临毕业前,应需求,花了三天写了个小的聊天工具,貌似简陋得很….若有机会再完善吧,目前毕业季,处理毕业事宜,还要准备即将的入职. 眼瞅着大学四年就这么结束了,哎. 开始吧,四篇博文简单介绍下基本实现,由 ...
- c#后台修改前台DOM的css属性
<div id = 'div1' runat="server">haha</div> ----------- 后台代码中这样调用 div1.Style[&q ...
- 教你50招提升ASP.NET性能(十一):避免在调试模式下运行网站
(17)Avoid running sites in debug mode 招数17: 避免在调试模式下运行网站 When it comes to ASP.NET, one of the most c ...
- AndroidStudio快捷键汇总
最近开始全面转向Android Studio开发了,经常要去查快捷键,索性汇总下,自己方便查找 IDE 按键 说明 F1 帮助 Alt(Option)+F1 查找文件所在目录位置 Alt(Option ...
- 怎样通过iPhone Safari 来安装测试版ipa
http://www.cocoachina.com/bbs/read.php?tid=94101# <?xml version="1.0" encoding="UT ...
- C++ 继承的访问权限
1.它解决什么问题?为什么设计出继承的各种访问权限? 可以这样认为,C++继承会把父类的东西拉到自己这里,这些东西都是自己的,父类中的字段和方法都有访问权限,如果我想改变这些东西的访问权限,该怎么办? ...
- [每日一题] 11gOCP 1z0-053 :2013-10-12 RESULT_CACHE在哪个池?.............................44
转载请注明出处:http://blog.csdn.net/guoyjoe/article/details/12657479 正确答案:B Oracle 11g 新特性:Result Cache , ...
- C#利用lambda表达式将函数作为参数或属性跨类传递
在编码时,由于开始是在winform下进行简单的测试开发的,后来代码多了,就想分到不同的类里边去,可是因为原来的测试是在同一个form下的,所以对于函数调用可以很方便,而一旦跨类之后,就会发现,这函数 ...