zoukankan      html  css  js  c++  java
  • 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);
            }
    
        }
    }

    代码不对,请告诉我哦.

  • 相关阅读:
    指定时间的月初和月末一天的写法
    EF写distinct
    服务的调试和安装
    EF写INNER JOIN 链接
    BZOJ 1825: [JSOI2010]蔬菜庆典
    P4171 [JSOI2010]满汉全席
    Educational Codeforces Round 71 (Rated for Div. 2) Solution
    P4292 [WC2010]重建计划
    P3724 [AH2017/HNOI2017]大佬
    P5504 [JSOI2011]柠檬
  • 原文地址:https://www.cnblogs.com/laxknight/p/3712918.html
Copyright © 2011-2022 走看看