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>
查看全文
相关阅读:
Eclipse 介绍
XML 解析之 dom4j 解析器
XPath 快速入门
XML 解析之 jaxp 解析器
XML 之快速入门
java操作Excel
识别jar的编译JDK版本
IntelliJ Idea 工具
单点登录SSO
java泛型-类型擦除
原文地址:https://www.cnblogs.com/firecode/p/2460892.html
最新文章
【ASP.NET MVC 学习笔记】- 01 理解MVC模式
jquery.validate.js表单验证
回车和换行的区别
Mysql Explain 参数解释
Visual Studio中让一个JS文件智能提示另一个JS文件中的成员
跟我学算法-xgboost(集成算法)基本原理推导
跟我学算法-PCA(降维)基本原理推导
跟我学算法-svm支持向量机算法推导
决策树与树集成模型(bootstrap, 决策树(信息熵,信息增益, 信息增益率, 基尼系数),回归树, Bagging, 随机森林, Boosting, Adaboost, GBDT, XGboost)
图片拼接SIFT
热门文章
图像特征与描述子(直方图, 聚类, 边缘检测, 兴趣点/关键点, Harris角点, 斑点(Blob), SIFI, 纹理特征)
跟我学算法-吴恩达老师(误差分析, 正确标注, 开发集和测试集的划分, 数据不匹配,迁移学习, 多任务学习, 端到端学习)
跟我学算法-吴恩达老师(正交化, 单实数评估指标, 满足指标, (训练集,开发集, 测试集的分布), 改变指标, 人类的表现 )
跟我学算法-吴恩达老师(超参数调试, batch归一化, softmax使用,tensorflow框架举例)
跟我学算法-opencv加载,修改,保存
Java 之图形验证码
HTTP 协议介绍
Tomcat 服务器介绍
Web 资源介绍
单元测试
Copyright © 2011-2022 走看看