zoukankan
html css js c++ java
两个Activity切换例子
Activity01
import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; public class Activity01 extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); /* 设置显示main.xml布局 */ Button button = (Button)this.findViewById(R.id.button1); button.setOnClickListener(new Button.OnClickListener(){ public void onClick(View v){ //新建一个Intent Intent intent = new Intent(); //制定intent要启动的类 intent.setClass(Activity01.this, Activity02.class); //启动一个新的Activity startActivity(intent); //关闭当前的 Activity01.this.finish(); } }); } }
Activity02
import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; public class Activity02 extends Activity{ /*savedInstanceState 保存当前Activity的状态信息。*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //调用父类的onCreate构造函数) /* 设置显示main2.xml布局 */ setContentView(R.layout.main2); /* findViewById(R.id.button2)取得布局main.xml中的button2 */ Button button = (Button) findViewById(R.id.button2); /* 监听button的事件信息 */ button.setOnClickListener(new Button.OnClickListener(){ public void onClick(View v){ /* 新建一个Intent对象 */ Intent intent = new Intent(); /* 指定intent要启动的类 */ intent.setClass(Activity02.this, Activity01.class); /* 启动一个新的Activity */ startActivity(intent); /* 关闭当前的Activity */ Activity02.this.finish(); } }); } }
strings.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="hello">第一个Activity</string> <string name="hello2">第二个Activity</string> <string name="app_name">Activity切换</string> </resources>
main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <Button android:layout_width="100px" android:layout_height="wrap_content" android:layout_x = "120px" android:layout_y = "90px" android:text ="切换" android:id="@+id/button1" > </Button> </LinearLayout>
main2.xml
<?xml version="1.0" encoding="UTF-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello2" /> <Button android:layout_width="100px" android:layout_height="wrap_content" android:layout_x = "120px" android:layout_y = "90px" android:text ="切换" android:id="@+id/button2" > </Button> </LinearLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="cn.lysine" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="7" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:name=".Activity01" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="Activity02"> </activity> </application> </manifest>
查看全文
相关阅读:
ASP.net 网站项目:Fckeditor使用StepByStep
SQL2005触发器写法
Android 中 PopupWindow使用
storyboard学习笔记-1
判断两矩形是否相交
CListCtrl 使用
字符串和数字之间的转换(Unicode)
【转】全特化/偏特化
判断点是否在多边形内——射线法
c++强制转化
原文地址:https://www.cnblogs.com/firecode/p/2460892.html
最新文章
SQL 2005 用户sa创建失败 解决方案
在 C# 中使用设置 Settings.settings
关于移动开发框架内容进程
AS3效率优化:使用Vector数据类型
amfphp中文乱码解决方法
Flex 开发移动
正则表达式
关于流程化解决方案(属于自己的一套制作解决方案)
SWFLibrary类加载外部资源库
新浪微博 Flash SDK
热门文章
getObjectsUnderPoint
【转】关于速度,加速度,弹性,缓动,摩擦力,重力等内容
如何为fckeditor文本编辑器增加图片删除功能
小兔子笑话全集,工作之余轻松下
IIS ASP.NET 1.1与2.0共存
如何配置 SQL Server 2005 以允许远程连接 微软转
变着法骂人的脑筋急转弯
修复移动硬盘“文件或目录损坏且无法读取”错误
C# 解决上传附件大小限制
DATALIST里再绑定个DATALIST
Copyright © 2011-2022 走看看