同一个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. 目前主流编译器对C++11特性的支持情况

    目前主流编译器对C++11特性的支持情况 1. GCC编译器(从编译器GCC4.8.X的版本完全支持) (1)目前C++11特性,之前成为C++0X特性,从GCC4.3的后续版本中逐步对C++11进行 ...

  2. win32多线程-异步(asynchronous) I/O

    I/O设备是个慢速设备,无论打印机.调制解调器,甚至硬盘,与CPU相比都奇慢无比,坐下来干等I/O的完成是一件不甚明智事情. 异步(asynchronous) I/O在win32多线程程序设计中被称为 ...

  3. SSO单点登录三种情况的实现方式详解(转载)

    单点登录(SSO——Single Sign On)对于我们来说已经不陌生了.对于大型系统来说使用单点登录可以减少用户很多的麻烦.就拿百度来说吧,百度下面有很多的子系统——百度经验.百度知道.百度文库等 ...

  4. [转载]MVC、MVP以及Model2(上)

    对于大部分面向最终用户的应用来说,它们都需要具有一个可视化的UI与用户进行交互,我们将这个UI称为视图(View).在早期,我们倾向于将所有与视图相关的逻辑糅合在一起,这些逻辑包括数据的呈现.用户操作 ...

  5. WebApi 插件式构建方案:重写的控制器获取工厂

    body { border: 1px solid #ddd; outline: 1300px solid #fff; margin: 16px auto; } body .markdown-body ...

  6. bootstrap-table简单使用

    开发项目时总想着能不能有一款插件包含分页,查询等常用功能,后来发现了bootstrap-table 直接看代码和效果图 <!DOCTYPE html> <html lang=&quo ...

  7. Session如何保存在sql数据库中

    aspnet中,session默认以inproc模式存储,也就是保存在iis进程中,这样有个优点就是效率高,但不利于为本负载均衡扩展.可以把session信息保存在SQL Server中,据说,该种方 ...

  8. roadflow asp.net工作流自定义表单

    在roadflow表单设计器不能满足很复杂的业务需求的时候,可以采用自定义表单(即表单页面自己做). 自定义表单就是自己写一个页面,包含控制器视图,然后将这个页面挂到流程上进行审批. 自定义表单分为以 ...

  9. RxJava / RxAndroid

    RxJava 是什么 RxJava 是函数响应式编程框架,它用观察者设计模式. 常用来做异步数据处理,在安卓中用来代替传统的 AsyncTask + Handler 的组合结构. RxJava 架构简 ...

  10. django系列3.1--url路由配置, 正则, 分发include, 分组命名匹配

    一.url配置 在django项目中urls.py文件中就是为这个url调用的view(视图)函数之间的映射表,来配置访问的一个url执行什么代码 默认的基本格式: from django.conf. ...