更改时,TextView.Text不会在屏幕上以可视方式更新

时间:2015-10-05 03:43:17

标签: java c# android

public void displayTimeOnScreen()
    {
        _timer = new System.Timers.Timer();
        _timer.Interval = 1000;
        _timer.Elapsed += Timer_Elapsed;
        _timer.Enabled = true;
        FindViewById<TextView>(Resource.Id.textViewDay).Text = "Test";//This works
    }

public void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
    {
        TextView timeTextView, dateTextView, dayTextView;

        LinearLayout screen = FindViewById<LinearLayout>(Resource.Id.box);
        bool portrate = screen.Height > screen.Width;

        timeTextView = FindViewById<TextView>(Resource.Id.textViewTime);
        dateTextView = FindViewById<TextView>(Resource.Id.textViewDate);
        dayTextView = FindViewById<TextView>(Resource.Id.textViewDay);

        string[] timeData = { "stuff", "things", "test" };

        timeTextView.Text = timeData[0];
        dateTextView.Text = timeData[1];
        dayTextView.Text = timeData[2];
        Log.Info("Information", timeTextView.Text);//This will tell me that timeTextView.Text has actually been updated, it just isn't showing on the screen
    }
}

所以我一直在尝试制作一个在Android设备上显示时间的简单程序。我使用Timers对象来运行应该更新时间的代码。但是,虽然Log告诉我代码正在运行并且TextView的文本值正在更新,但这并未显示在Android设备的屏幕上。 displayTimeOnScreen()方法确实有效。

有谁知道问题可能是什么?

2 个答案:

答案 0 :(得分:0)

您正在寻找的方法是textView.setText()

答案 1 :(得分:0)

您需要使用setText()TextView中显示文字。

timeTextView.setText(timeData[0]);
dateTextView.setText(timeData[1]);
dayTextView.setText(timeData[2]);