0
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()
方法確實起作用。TextView.Text將不會更新屏幕上的視覺更新
有誰知道這個問題可能是什麼?
我已經嘗試過'setText()'和我有完全相同的問題。 'TextView.Text = string'絕對可行,因爲'displayTimeOnScreen()'方法中的一個確實改變了文本。我很確定它與Timer有關,但不知道是什麼。 – CSalisbury