1

I'm developing a widget in Android, and I need a time ago field with just minutes. So, I don't like to make a Workmanager and update this field by partially updating each minute. So, I found a solution to use a chronometer, but unfortunately I can't find a way to just showing the value of it as minutes without seconds and hours.

check the sample below:

<Chronometer
    android:id="@+id/text_ago"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@id/img_bg"
    android:layout_marginStart="40dp"
    android:layout_marginBottom="19dp"
    android:format="%s ago"
    />


private fun updateHomeWidget(
context: Context,
appWidgetManager: AppWidgetManager,
appWidgetId: Int
) {
val views = RemoteViews(context.packageName, R.layout.home_widget)
views.setChronometer(
    R.id.text_ago,
    SystemClock.elapsedRealtime() - 50*1000,
    "%s ago",
    true
)
views.setTextViewText(R.id.text_message, "Testing...")


appWidgetManager.updateAppWidget(appWidgetId, views)

}

Any help, Thanks!

M.SH
  • 357
  • 2
  • 8
  • 22

0 Answers0