簡體   English   中英

我如何將計時器從一個片段傳遞到另一個片段?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM