同一个Activity先后加载2个Layout,从layout1取值传入layout2
同一个Activity先后加载2个Layout,从layout1取值传入layout2
没啥技术含量,就权当丰富下mono for android的小代码.
Main.xaml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/txtuser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="账号:" />
<EditText
android:id="@+id/username"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtuser" />
<TextView
android:id="@+id/txtpass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/username"
android:text="密码:" />
<EditText
android:id="@+id/password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtpass"
android:password="true" />
<Button
android:id="@+id/ok"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="OK,Now Next" />
<Button
android:id="@+id/cancel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Cancel" />
</LinearLayout>
Info.xaml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:text="用户名:"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/username2" />
<TextView
android:text="密码:"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/password2" />
</LinearLayout>
Activity1.cs
using System; using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS; namespace layoutAvaluetolayoutB
{
[Activity(Label = "layoutAvaluetolayoutB", MainLauncher = true, Icon = "@drawable/icon")]
public class Activity1 : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle); // Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
EditText username = FindViewById<EditText>(Resource.Id.username);
EditText password = FindViewById<EditText>(Resource.Id.password);
Button btnOK = FindViewById<Button>(Resource.Id.ok);
//btnOK.Click += delegate { showinfo(this,username.Text, password.Text); };//版本1
btnOK.Click += delegate { showinfo(username, password); };//版本2
//btnOK.Click += (sender, e) =>
//{
// EditText username = FindViewById<EditText>(Resource.Id.username);
// EditText password = FindViewById<EditText>(Resource.Id.password);
// AlertDialog.Builder dlg = new AlertDialog.Builder(this);
// dlg.SetTitle("提示");
// dlg.SetMessage(string.Format("你输入的账号是:{0},密码是:{1}", username.Text, password.Text));
// dlg.SetPositiveButton("确定", delegate { });
// dlg.Show();
//}; }
#region //版本1
//private Activity context = null;
//public void showinfo(Activity ac, string username, string password)
//{
// this.context = ac;
// context.SetContentView(Resource.Layout.Info);
// TextView username2 = FindViewById<TextView>(Resource.Id.username2);
// TextView password2 = context.FindViewById<TextView>(Resource.Id.password2);
// username2.SetText(username, TextView.BufferType.Normal);
// password2.SetText(password, TextView.BufferType.Normal);
// //context.SetContentView(Resource.Layout.Info);
//}
#endregion
//版本2
public void showinfo(EditText username, EditText password)
{
SetContentView(Resource.Layout.Info);
FindViewById<TextView>(Resource.Id.username2).SetText("用户名:" + username.Text, TextView.BufferType.Normal);
FindViewById<TextView>(Resource.Id.password2).Text += password.Text;
}
} }
同一个Activity先后加载2个Layout,从layout1取值传入layout2的更多相关文章
- Activity的加载模式及Intent.setFlags
在多Activity开发中,有可能是自己应用之间的Activity跳转,或者夹带其他应用的可复用Activity.可能会希望跳转到原来某个Activity实例,而不是产生大量重复的Activity. ...
- Android四种Activity的加载模式(转)
建议首先阅读下面两篇文章,这样才可以更好的理解Activity的加载模式: Android的进程,线程模型: http://www.cnblogs.com/ghj1976/archive/2011/0 ...
- 通过Activity动态加载Fragment创建主界面构架
在做项目中,需要建立一个主界面框架,尝试过使用ViewPager ,后来又换成了使用Activity动态加载Fragment实现选项卡的效果.总结一下方便以后回顾. 先给出总体效果: 要实现上述效果, ...
- Android四种Activity的加载模式
建议首先阅读下面两篇文章,这样才可以更好的理解Activity的加载模式: Android的进程,线程模型 http://www.cnblogs.com/ghj1976/archive/2011/04 ...
- Android Activity的加载模式和onActivityResult方法之间的冲突
前言 今天在调试程序时,发现在某一Activity上点击返回键会调用该Activity的onActivityResult()方法.我一开始用log,后来用断点跟踪调试半天,还是百思不得其解.因为之前其 ...
- android源码解析(十七)-->Activity布局加载流程
版权声明:本文为博主原创文章,未经博主允许不得转载. 好吧,终于要开始讲讲Activity的布局加载流程了,大家都知道在Android体系中Activity扮演了一个界面展示的角色,这也是它与andr ...
- 在主Android Activity中加载Fragment的一般简易方法 ,来模拟一个微信界面。
在Fragment的生命周期中,需要重点关注onCreate.onCreateView.onViewCreated.Activity与Fragment生命周期在设计模式上大体一致. package c ...
- ANDROID基础ACTIVITY篇之Activity的加载模式
在这之前首先让我们先了解一下什么是Task Task,简单的说,就是一组以栈的模式聚集在一起的Activity组件集合.它们有潜在的前后驱关联,新加入的Activity组件,位于栈顶,并仅有在栈顶的A ...
- [转]Android Activity的加载模式和onActivityResult方法之间的冲突
前言 今天在调试程序时,发现在某一Activity上点击返回键会调用该Activity的onActivityResult()方法.我一开始用log,后来用断点跟踪调试半天,还是百思不得其解.因为之前其 ...
随机推荐
- ACTIVITI 5.14事件监听器的BUG
在ACTIVITI 5.14中,测试内部子流程时发现事件定义的事件监听器不能触发. <activiti:executionListener event="start" del ...
- S5PV210定时器
在S5PV210内部,一共有4类定时器件.这4类定时器件的功能.特征是不同的. 1.PWM定时器(1)这种是最常用的,平时所说的定时器一般指的是这个.像简单单片机(譬如51单片机)中的定时器也是这类. ...
- python sublime run快捷键设置
一.Ctrl+Shift+P进行插件“sublimeREPL”安装 二.打开preferences->Key Binding-User,写入以下内容 [ { "keys": ...
- swoole实现websocket推送
环境配置: swoole 1.9.3.centos6.5(虚拟机).PHP7.01 思路: ①通过server中的collections取出fd ②写一个admin. ...
- 从Objective-C到Swift,你必须会的(一)#pragma mark
在Objective-C里,为了让代码组织的有序也方便用control+6的快捷键在Xcode中查找,所以出现了一个大家都很熟悉的东东.这就是:#prama mark. #pragma mark 但 ...
- Shell编程-04-Shell中变量数值计算
目录 算术运算符 算术运算命令 数值运算用法 算术运算符 在任何一门形式的语言中均会存在算术运算的情况,Shell常见的运算符如下所示: 运算符 含义 + - * / % 加 减 乘 除 求余 ...
- ZOJ1586 QS Network 2017-04-13 11:46 39人阅读 评论(0) 收藏
QS Network Time Limit: 2 Seconds Memory Limit: 65536 KB Sunny Cup 2003 - Preliminary Round Apri ...
- HDU2680 Choose the best route 2017-04-12 18:47 28人阅读 评论(0) 收藏
Choose the best route Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Othe ...
- ubuntu解压文件命令大全
ubuntu 下rar解压工具安装方法: 压缩功能 安装 sudo apt-get install rar 卸载 sudo apt-get remove rar 解压功能 安装 sudo apt-ge ...
- 记一次Angular2环境搭建及My First Angular App小demo呈现
参考连接?不如说是照搬链接.AngularJs官网地址快速起步地址. 对于一个一直只是用jq,偶尔学习点Knockout js,了解一点mvvm结构的前端来说,学习Angular2还是有点困难的.好了 ...