• 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);
            }
    
        }
    }

    代码不对,请告诉我哦.

  • 相关阅读:
    PHP基本语法
    SQL-还原数据库,数据库提示正在还原中的处理办法
    MyBatis学习笔记
    Java byte数据转换和处理总结
    JS和JQUERY的区别
    .NET 之 ORM 性能评测
    你必须知道的 SmartSql !
    SmartSql 介绍
    SmartSql 入门
    SmartCode.ETL 这不是先有鸡还是蛋的问题!
  • 原文地址:https://www.cnblogs.com/laxknight/p/3712918.html
Copyright © 2020-2023  润新知