zoukankan      html  css  js  c++  java
  • 第二课 两个视图+数据传输

    项目结构如下图:

    image

    比第一课多了一个活动(Activity)。

    1.Activity1.cs代码如下:

    using System;
     
    using Android.App;
    using Android.Content;
    using Android.Runtime;
    using Android.Views;
    using Android.Widget;
    using Android.OS;
    using Android.Util;
     
    namespace MyLesson
    {
        [Activity(Label = "Lesson2_View1", MainLauncher = true, Icon = "@drawable/icon")]
        public class Lesson21 : Activity
        {
     
            protected override void OnCreate(Bundle bundle)
            {
                base.OnCreate(bundle);
     
                LinearLayout layout = new LinearLayout(this);
                layout.Orientation = Orientation.Vertical;
     
                TextView tv = new TextView(this);
                tv.Text = "这是第一个视图";
     
                Button b = new Button(this);
                b.Text = "点击切换到第二个视图";
                b.Click += b_Click;
     
                layout.AddView(tv);
                layout.AddView(b);
                SetContentView(layout);
            }
     
            void b_Click(object sender, EventArgs e)
            {
                Intent intent = new Android.Content.Intent(this, typeof(Lesson22));
                intent.PutExtra("MessageName", "你好,这里是视图1");
                StartActivity(intent);
            }
        }
    }
     

    2.Activity2.cs代码如下:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
     
    using Android.App;
    using Android.Content;
    using Android.OS;
    using Android.Runtime;
    using Android.Views;
    using Android.Widget;
     
    namespace MyLesson
    {
        [Activity(Label = "Lesson2_view2")]
        public class Lesson22 : Activity
        {
            protected override void OnCreate(Bundle bundle)
            {
                base.OnCreate(bundle);
     
                LinearLayout layout = new LinearLayout(this);
                layout.Orientation = Orientation.Vertical;
     
                TextView tv = new TextView(this);
                tv.Text = "这是第二个视图,来自第一个视图的数据是:" + (Intent.GetStringExtra("MessageName") ?? "没说什么");
     
     
                layout.AddView(tv);
                
                SetContentView(layout);
            }
        }
    }
  • 相关阅读:
    [置顶] windows player,wzplayerV2 for windows
    wzplayer 近期将会支持BlackBerry和WinPhone8
    wzplayerEx for android(真正硬解接口,支持加密的 player)
    ffmpeg for ios 交叉编译 (支持i686 armv7 armv7s) 包含lame支持
    ffmpeg for ios 交叉编译 (支持i686 armv7 armv7s) 包含lame支持
    编译cegcc 0.59.1
    wzplayer 近期将会支持BlackBerry和WinPhone8
    wzplayerEx for android(真正硬解接口,支持加密的 player)
    windows player,wzplayerV2 for windows(20140416)更新
    编译cegcc 0.59.1
  • 原文地址:https://www.cnblogs.com/catzhou/p/3579972.html
Copyright © 2011-2022 走看看