同一个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的更多相关文章

  1. Activity的加载模式及Intent.setFlags

    在多Activity开发中,有可能是自己应用之间的Activity跳转,或者夹带其他应用的可复用Activity.可能会希望跳转到原来某个Activity实例,而不是产生大量重复的Activity. ...

  2. Android四种Activity的加载模式(转)

    建议首先阅读下面两篇文章,这样才可以更好的理解Activity的加载模式: Android的进程,线程模型: http://www.cnblogs.com/ghj1976/archive/2011/0 ...

  3. 通过Activity动态加载Fragment创建主界面构架

    在做项目中,需要建立一个主界面框架,尝试过使用ViewPager ,后来又换成了使用Activity动态加载Fragment实现选项卡的效果.总结一下方便以后回顾. 先给出总体效果: 要实现上述效果, ...

  4. Android四种Activity的加载模式

    建议首先阅读下面两篇文章,这样才可以更好的理解Activity的加载模式: Android的进程,线程模型 http://www.cnblogs.com/ghj1976/archive/2011/04 ...

  5. Android Activity的加载模式和onActivityResult方法之间的冲突

    前言 今天在调试程序时,发现在某一Activity上点击返回键会调用该Activity的onActivityResult()方法.我一开始用log,后来用断点跟踪调试半天,还是百思不得其解.因为之前其 ...

  6. android源码解析(十七)-->Activity布局加载流程

    版权声明:本文为博主原创文章,未经博主允许不得转载. 好吧,终于要开始讲讲Activity的布局加载流程了,大家都知道在Android体系中Activity扮演了一个界面展示的角色,这也是它与andr ...

  7. 在主Android Activity中加载Fragment的一般简易方法 ,来模拟一个微信界面。

    在Fragment的生命周期中,需要重点关注onCreate.onCreateView.onViewCreated.Activity与Fragment生命周期在设计模式上大体一致. package c ...

  8. ANDROID基础ACTIVITY篇之Activity的加载模式

    在这之前首先让我们先了解一下什么是Task Task,简单的说,就是一组以栈的模式聚集在一起的Activity组件集合.它们有潜在的前后驱关联,新加入的Activity组件,位于栈顶,并仅有在栈顶的A ...

  9. [转]Android Activity的加载模式和onActivityResult方法之间的冲突

    前言 今天在调试程序时,发现在某一Activity上点击返回键会调用该Activity的onActivityResult()方法.我一开始用log,后来用断点跟踪调试半天,还是百思不得其解.因为之前其 ...

随机推荐

  1. Exception in thread "main" java.lang.Error: Unresolved compilation problem

    初学java,使用eclipse编译时,可能会遇到如下图所示的编译错误(Exception in thread "main" java.lang.Error: Unresolved ...

  2. mysql - json串新增字段

    1.建表 -- 建表 drop table if exists ta_product2; CREATE TABLE ta_product2( id int primary key auto_incre ...

  3. CodeForces - 669D——(思维题)

    Little Artem is fond of dancing. Most of all dances Artem likes rueda — Cuban dance that is danced b ...

  4. EBS 并发程序运行信息

    --并发程序运行信息SELECT REQUEST_ID,       PROGRAM,       actual_start_date 开始日期,       ACTUAL_COMPLETION_DA ...

  5. Oracle EBS Standard Package Function Add User & Resp

    Oracle EBS Standard Package Function Add User & Resp. fnd_user_pkg.CreateUser; fnd_user_pkg.AddR ...

  6. delphi http 403 获取不到服务器返回的错误消息 用浏览器打开url可以返回

    用delphi的idhttp Get一个url如下: http://117.135.237.4:9090/agent/api/treatmentModeUpdate?userName=VDAwMIMQ ...

  7. 安装配置BITS上传服务

    IIS 6.0和IIS 7.0 支持安装BITS上传组件. 下面以IIS7.0为例安装配置bits上传服务. 1.安装 首先确定服务器已经按装IIS服务.依次打开服务管理器->功能->添加 ...

  8. C# Aes CryptoStream Specified padding mode is not valid for this algorithm的解決方法

    //解密數據            using (var ss = File.OpenRead(@"d:\qq.d.flac"))            {             ...

  9. windows过滤指定IP

    通过windows的安全管理策略工具我们可以实现对IP的过滤.整个过程比较复杂.我们以图形演示. 下面我们以windows 8.1作为示例. 1.控制面板=>管理工具=>本地安全策略. 2 ...

  10. Ocelot 新手上路

    新手上路,老司机请多多包含!Ocelot 在博园里文章特别多,但是按照其中一篇文章教程,如果经验很少或者小白,是没法将程序跑向博主的结果. 因此总结下     参考多篇文章,终于达到预期效果. Oce ...