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()
方法确实有效。
有谁知道问题可能是什么?
答案 0 :(得分:0)
您正在寻找的方法是textView.setText()
答案 1 :(得分:0)
您需要使用setText()
在TextView
中显示文字。
timeTextView.setText(timeData[0]);
dateTextView.setText(timeData[1]);
dayTextView.setText(timeData[2]);