0
フラグメントAにTextView
を使用するタイマーがあるとします。このタイマーをフラグメントBで使用したいと思います。どうすればいいですか?これはどのようにして、ある断片から別の断片にタイマーを渡すのですか?
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に関連付けられたタイマーを使用したい...タイマーを設定するために、フラグメントAで使用されているコードです。
どうすれば解決できますか?
ありがとうございます!
メインスレッドの外部からUIを更新しないでください。 – dazito
説明していただけますか? –
この質問への説明を確認してください:http://stackoverflow.com/questions/4369537/update-ui-from-thread *しかし、AsyncTaskは使用しないでください。後で問題に遭遇します。デバイス)。それについてもっと読む:http://simonvt.net/2014/04/17/asynctask-is-bad-and-you-should-feel-bad/ – dazito