学习EditText和Button控件

以下内容全部或部分转自或参考于网络。

有了学习TextView控件的基础,打算接下来多学习几个控件。

一、Button控件

新建Android应用时,会自带一个Button控件,对应代码如下

        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 { button.Text = string .Format("{0} clicks!", count++); };
        }

二、EditText控件

在工具箱内分类归到了“Text Fields”分组中:Number,Password,Phone等。

三、Spinner控件

下面只列出了代码

    public class MainActivity : Activity
    {
        Spinner state;
        TextView tvsp;
        ArrayAdapter<string > aas;
        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
            state = FindViewById< Spinner>(Resource .Id.sp);
            tvsp = FindViewById< TextView>(Resource .Id.tvsp);
            aas = new ArrayAdapter <string>( this,
                Android. Resource.Layout .SimpleDropDownItem1Line);
            state.Adapter = aas;
            aas.Add( String.Empty);
            aas.Add( "Alabbama");
            aas.Add( "California");
            aas.Add( "texas");
            state.ItemSelected += new EventHandler <AdapterView. ItemSelectedEventArgs>(sp_ItemSelected);


        }
        void sp_ItemSelected(object sender, AdapterView. ItemSelectedEventArgs e)
        {
            tvsp.Text = Convert.ToString(aas.GetItem(e.Position));
        }
    }

代码中AdapterView. ItemSelectedEventArgs和书上不一样(没有AdapterView 部分),估计是版本升级的原因。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值