单击按钮时从字符串数组到textview的结果

时间:2018-09-10 14:51:57

标签: c# android xamarin

https://s8.postimg.cc/nryfeo8xh/Screenshot_8.png

我有一些代码,当单击按钮时,必须将数组的字符串结果添加到textView中。

它有3个组成部分 文字检视 editText 按钮

存在一个数组,其结果是,单击按钮时必须将其上的editText添加到textView上,并在数组随机结果的顶部

  1. 第一次尝试

    • editText =嗨
    • 点击按钮
    • textview =

    • 你好

    • 三个(来自数组随机结果)
  2. 第二次尝试

    • editText =再次喜好
    • 点击按钮
    • textview =

    • 再见

    • 两个
    • 你好(先前的结果)
    • 三个(先前的结果)

文本视图几乎是一个日志文件

using Android.App;
using Android.Widget;
using Android.OS;
using System;

namespace APP
{

    [Activity(Label = "APP", MainLauncher = true)]
    public class MainActivity : Activity
    {
        string[] constStringArray = new string[] { "one", "two", "three" };


        TextView res;
        EditText edt;
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            edt = FindViewById<EditText>(Resource.Id.editText1);
            res = FindViewById<TextView>(Resource.Id.textView1);
            Button btn = FindViewById<Button>(Resource.Id.button1);

            btn.Click += Btn_Click;

        }

        private void Btn_Click(object sender, System.EventArgs e)
        {

            string constStringArray = res.Text.ToString();

            res.Text = constStringArray;
        }
    }
}

0 个答案:

没有答案