[英]How would i pass a timer from one fragment to another?
假設我有一個在片段A中使用TextView
的計時器。我想在片段B中使用此計時器。我該怎么做? 這是片段A中用於設置計時器的代碼...
private Runnable mUpdateTimeTask = new Runnable() {
public void run() {
long totalDuration = mp.getDuration();
long currentDuration = mp.getCurrentPosition();
// Displaying total duration time
songTotalDurationLabel.setText(""+utils.milliSecondsToTimer(totalDuration));
// Displaying current time
songCurrentDurationLabel.setText(""+utils.milliSecondsToTimer(currentDuration));
// Running this thread after 100 milliseconds
mHandler.postDelayed(this, 100);
}
};
現在,我也想使用與片段B中與songCurrentDurationLabel
TextView關聯的計時器。
我將如何解決這個問題?
謝謝!
在主機活動中使用計時器,並將結果設置/發布為回調。 Android UI工具包不是線程安全的-請勿從UI線程外部訪問UI。
檢查一些陷阱 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.