无法打印字符串(Xamarin Android)

时间:2018-01-24 08:49:14

标签: xamarin.android eddystone

//Beacon MAC Address
string B1 = "E9:32:C6:D9:91:A6";
string B2 = "FA:46:4D:77:C9:9B";
string B3 = "E7:6D:97:D4:83:14";

//Testing
string MAC1;
string Telemetry;
string test;
protected override void OnCreate(Bundle savedInstanceState)
{
    base.OnCreate(savedInstanceState);

    //Create beacon manager
    beaconManager = new BeaconManager(this);

    //Connect to beacon manager to start scanning
    beaconManager.Connect(this);

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

    Button Scan = FindViewById<Button>(Resource.Id.Scan);
    TextView B_Name = FindViewById<TextView>(Resource.Id.B_Name);
    TextView B_Rssi = FindViewById<TextView>(Resource.Id.B_Rssi);
    TextView B_MacAddress = FindViewById<TextView>(Resource.Id.B_MacAddress);

    TextView Check = FindViewById<TextView>(Resource.Id.Check);

    Scan.Click += Scan_Click;

    int num1 = 0;

    eddystone = new Eddystone[3];

    //Create an ArrayList
    ArrayList arrayList = new ArrayList();

    // Wearables will be triggered when nearables are found
    beaconManager.Eddystone += (sender, e) =>
    {
        ActionBar.Subtitle = string.Format("Found {0} eddystones.", e.Eddystones.Count);

        B_MacAddress.Text = "MAC Address " + e.Eddystones[0].MacAddress;
        B_Rssi.Text = "Rssi " + e.Eddystones[0].Rssi;

        e.Eddystones.CopyTo(eddystone, num1);
        arrayList.Add(e.Eddystones[0].MacAddress);
        MAC1 = "Lol";
    };
    Check.Text = MAC1 + " jasdh";
}

我的代码需要一些帮助。

目前,我已经定义了一个名为MAC1的字符串。但是,我在beaconManager.Eddystone内定义了它,然后尝试将其显示出来。那没起效。它只显示jasdh

我不明白为什么。谁能告诉我原因?

1 个答案:

答案 0 :(得分:0)

您没有在变量MAC1中看到文本,因为您将textview Check设置为“jasdh”。在提供的代码中,您实际上并未更新beaconManager.Eddystone块中的Check textview。使用Check.Text =

将Check文本设置为您想要的代码块,方法与下面相同