• Xamarin.Android之山有木兮之木有枝,心悦君兮君不知。


                                                                                      Xamarin.Android之山有木兮之木有枝,心悦君兮君不知。

     第一步,写项目中的第一个界面。

    <?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/tv"
         android:layout_width= "fill_parent "
          android:layout_height="wrap_content"
          android:text="小晕,不醉。  先生:"
        />
     
      <Button
        android:id= "@+id/IntentBtn "
        android:layout_width= "fill_parent "
        android:layout_height= "wrap_content "
        android:text= "我说上联 "
        />
    </LinearLayout>

    第二步写项目中的第二个界面。

    
    
    <?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/tv "
       android:layout_width= "fill_parent "
        android:layout_height= "wrap_content "
        android:text= "你好,请问美国怎么走?  女士: "
        />
     
      <Button
        android:id= "@+id/btnClose "
         android:layout_width= "fill_parent "
        android:layout_height= "wrap_content "
        android:text= "我答下联 "
        />
    </LinearLayout>
     

    第三步,写项目中的第一个界面的逻辑。

    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 App1
    {
        [Activity(Label = "HelloIntent",MainLauncher= true ,@Icon = "@drawable/Icon")]
        public class HelloIntent : Activity
        {
            protected override void OnCreate( Bundle bundle)
            {
                base.OnCreate(bundle);
                SetContentView( Resource. Layout.HelloIntentLayout);
                Button button = FindViewById< Button>( Resource. Id.IntentBtn);
                button.Click += button_Click;
            }
     
            void button_Click( object sender, EventArgs e)
            {
                #region 简单意图到另外一个界面去
                //Intent it = new Intent();
                //it.SetClass(this, typeof(HelloIntent2));
                //StartActivity(it);
                #endregion
     
                string sendValue = "山有木兮木有枝" ;
                Toast.MakeText( this, sendValue, ToastLength.Short).Show();
                #region 显示传值               
                Intent it = new Intent();
                it.SetClass( this, typeof( HelloIntent2));
                it.PutExtra( "testName", sendValue);
                //此为普通调用。
              //  StartActivity(it);
                //当有返回值时用到,前一个参数是intent的对象,第一个是OnActivityResult方法里的requestCode。
                StartActivityForResult(it, 0);
                #endregion
            }
     
            protected override void OnActivityResult( int requestCode, Result resultCode, Intent data)
            {
                base.OnActivityResult(requestCode, resultCode, data);
                if (requestCode==0)
                {
                    if ( Result.Ok==resultCode)
                    {
                        string name = data.GetStringExtra( "nameExtra");
                        Toast.MakeText( this, name, ToastLength.Short).Show();
                    }
                }
            }
        }
    }

    第四步,写项目中的第二个界面的逻辑

    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 App1
    {
        [Activity(Label = "HelloIntent2")]
        public class HelloIntent2 : Activity
        {
            protected override void OnCreate( Bundle bundle)
            {
                base.OnCreate(bundle);
               SetContentView( Resource. Layout.HelloIntentLayout2);
                #region 显示传递参数,这边要得到传递过来的值。
                string uName = Intent.GetStringExtra( "testName");
                Toast.MakeText( this, uName, ToastLength.Long).Show();
                #endregion
     
                Button btnClose = FindViewById< Button>( Resource. Id.btnClose);
                btnClose.Click += btnClose_Click;
            }
     
            void btnClose_Click( object sender, EventArgs e)
            {
                string sendValue = "心悦君兮君不知" ;
                Toast.MakeText( this, sendValue, ToastLength.Short).Show();
                Intent it = new Intent();
                it.PutExtra( "nameExtra", sendValue);
                SetResult( Result.Ok,it);
                Finish();
            } 
        }
    }

    故事情节:

     小伙子向暗恋的小姑娘说了一句话,他说:山有木兮木有枝。

    小姑娘看到了小伙子说的话(成功将值带入到第二个界面):

         

    小姑娘在思索中,应该怎么回自己也心仪的小伙子呢。

    于是,她想到了,她羞答答的,她回了,她说心悦君兮君不知。


    然后小伙子看到了小姑娘的话,小伙子满意的笑了。

     

    学习内容

    签于太简单,略。请自行看官网

  • 相关阅读:
    PsySH——PHP交互式控制台
    PHP通过ssh或socks5读取远程服务器的mysql数据库
    构建:vue项目配置后端接口服务信息
    module.exports用法
    PhpStorm连接服务器,开始自动上传功能
    JavaScript Array.some()方法用法
    vue-router query和params传参(接收参数),$router、$route的区别
    ES6箭头函数(Arrow Functions)
    工作中常用到的ES6语法
    VueJs2.0建议学习路线
  • 原文地址:https://www.cnblogs.com/anmutu/p/Xamarin.html
Copyright © 2020-2023  润新知