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>
查看全文
相关阅读:
mybatis-plus物理分页插件使用
mybatis-plus提供支持ActiveRecord模式
mybatis-plus通用Service
mybatis-plus返回查询总记录数
Mybatis-Plus查询返回Map类型数据
Mybatis-Plus条件构造器condition动态判断条件
Mybatis-Plus条件构造器select方法返回指定字段
mybatis-plus条件构造器UpdateWrapper实例
mybatis-plus条件构造器QueryWrapper实例
这玩意比ThreadLocal叼多了,吓得why哥赶紧分享出来。
原文地址:https://www.cnblogs.com/firecode/p/2460892.html
最新文章
Netty源码分析之ByteBuf(一)—ByteBuf中API及类型概述
.NET Core使用NPOI将Excel中的数据批量导入到MySQL
SQL Server通过创建临时表遍历更新数据
ASP.NET Core 3.x Razor视图运行时刷新实时编译
利用RNN进行中文文本分类(数据集是复旦中文语料)
可变数据类型不能作为python函数的参数
pyspark读取pickle文件内容并存储到hive
pycaret之模型部署
pycaret模型分析
pycaret模型分析之绘制模型结果
热门文章
pycaret之集成模型(集成模型、混合模型、堆叠模型)
pycaret之训练模型(创建模型、比较模型、微调模型)
更简易的机器学习-pycaret的安装和环境初始化
python中各种操作的时间复杂度
Mac 效率工具必备神器 —— Alfred
详尽的 Elasticsearch7.X 安装及集群搭建教程
windbg分析dump-解决mscorwks不匹配
使用阿里云OSS的服务端签名后直传功能
nginx如何限制并发连接请求数?
mybatis-plus lambda条件构造器
Copyright © 2011-2022 走看看