Activity调用静态方法改变UI,使用Handler来改变UI显示

本人菜鸟,请各位多多指点,不足之处,请斧正.没啥技术含量,就权当丰富下mono for android的小代码.

 

Activity调用静态方法改变UI

using System;



using Android.App;

using Android.Content;

using Android.Runtime;

using Android.Views;

using Android.Widget;

using Android.OS;



namespace AndroidApplication1

{

    [Activity(Label = "AndroidApplication1", MainLauncher = true, Icon = "@drawable/icon")]

    public class Activity1 : Activity

    {

        int count = 1;



        protected override void OnCreate(Bundle bundle)

        {

            base.OnCreate(bundle);



            // Set our view from the "main" layout resource

            SetContentView(Resource.Layout.Main);



            // Get our button from the layout resource,

            // and attach an event to it

            Button button = FindViewById<Button>(Resource.Id.MyButton);



            button.Click += delegate { Class1.fun("改变一下咯", button); };

        }

    }

}

使用Handler来改变UI显示

using System;

using System.Collections.Generic;

using System.Text;

using Android.App;

using Android.OS;

using Android.Widget;

namespace AndroidApplication1

{

    public static class Class1

    {

        public static void fun(string str, Button button)

        {

            Java.Lang.Runnable rb;

            Handler handler = new Handler();

            rb = new Java.Lang.Runnable(() =>

            {

                button.Text = str;

            });

            handler.PostDelayed(rb, 1000);

        }



    }

}

代码不对,请告诉我哦.

你可能感兴趣的:(Activity)