使用计时器-在setText之后,Textview仅显示文本一秒钟

时间:2019-04-03 22:48:58

标签: java android

我正在创建一个时间跟踪应用程序,希望有一个可以启动/暂停/重置的秒表。当我按下“结束日期并保存”按钮时,我希望该应用程序在下面的TevtView中显示经过的小时/分钟/秒。它可以,但是只持续一秒钟,然后消失。我要去哪里错了?

我尝试创建一个仅用于更新TextView的新方法,但此后根本不显示。 如果有帮助,我必须在该项目中使用的最低SDK版本为23。

'On new blank Workbook Open
Private Sub App_NewWorkbook(ByVal Wb As Workbook)
    Set cwb = ThisWorkbook
    If Wb.Name <> cwb.Name Then
        Dim opFile As Variant
        Application.DisplayAlerts = False
        Wb.Close False
        opFile = Shell("EXCEL /X ", vbNormalFocus)
        Application.DisplayAlerts = True
    End If
End Sub
'On File Workbook Open
Private Sub App_WorkbookOpen(ByVal Wb As Workbook)
    Set cwb = ThisWorkbook
    If Wb.Name <> cwb.Name Then
        Dim fDir As String, opFile As Variant
        fDir = Wb.Path & "\" & Wb.Name
        Application.DisplayAlerts = False
        Wb.Close False
        opFile = Shell("EXCEL /X """ & fDir & """", vbNormalFocus)
        Application.DisplayAlerts = True
    End If
End Sub

1 个答案:

答案 0 :(得分:0)

为什么您要发射3次trackTodayActivity?这项活动有用吗?

要显示结果,这应该足够了:

public void stopAndSaveChronometer(View v) {
  if (running) {
    chronometer.stop();
    running = false;
    time = SystemClock.elapsedRealtime() - chronometer.getBase();
    h = (int) (time / 3600000);
    m = (int) (time - h * 3600000) / 60000;
    s = (int) (time - h * 3600000 - m * 60000) / 1000;

    displayTheTime = String.valueOf(h) + " hours, "
            + String.valueOf(m) + " minutes, "
            + String.valueOf(s) + " seconds";

    // display the times in the Textview
    showMyTime.setText(displayTheTime);

  }
}

这可以通过您的活动中的onCreate方法来完成:

showMyTime = (TextView) findViewById(R.id.printsavedTime);