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>
查看全文
相关阅读:
mysql优化——语句优化小技巧
mysql优化——索引与索引优化
Mysql存储引擎
Mysql优化技术
数据库设计——三范式
java多线程(二)——用到的设计模式
java多线程(一)
ubuntu下如何查看用户登录及用户操作相关信息
hdu 2546
hdu 2955
原文地址:https://www.cnblogs.com/firecode/p/2460892.html
最新文章
栈应用-中缀表达式转后缀表达式并计算值
SQL Server 订单分析
SQL Server 查询产品数量
DiterRams“设计十原则”
SQL Server 按月统计订单量
Good UI--UI设计原则<转>
SQL如何取日期中的年月
SPSS筛选有效省份
SQL Server 批量数据导入
第五章 列表、元组和字符串[DDT书本学习 小甲鱼]【6】
热门文章
第五章 列表、元组和字符串[DDT书本学习 小甲鱼]【5】
第五章 列表、元组和字符串[DDT书本学习 小甲鱼]【4】
第五章 列表、元组和字符串[DDT书本学习 小甲鱼]【3】
第五章 列表、元组和字符串[DDT书本学习 小甲鱼]【2】
第五章 列表、元组和字符串[DDT书本学习 小甲鱼]【1】
第四章 了不起的分支和循环[DDT书本学习 小甲鱼]【2】
第四章 了不起的分支和循环[DDT书本学习 小甲鱼]【1】
第三章 必须知道的一些基础知识[DDT书本学习 小甲鱼]【4】
scrapy系列教程一——scrapy介绍和scrapy安装
Linux——wc命令
Copyright © 2011-2022 走看看