java - 我如何从文本时钟中获取值

标签 java android string android-studio

在我的应用程序中,我有一个显示当前小时的文本时钟,当我单击一个按钮以从文本时钟获取值并将其放入字符串变量中时,我想这样做。我有这样的:

TextClock time = (TextClock) findViewById(R.id.horas);
horas = time.getText().toString();

在我的布局中,textclock 是这样的:

<TextClock
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/horas"
    android:textSize="30dp"
    android:layout_below="@+id/space2"
    android:layout_centerHorizontal="true" />

但是它返回一个空值。

最佳答案

应该这样做:

time.getFormat12Hour();

或:

time.getFormat24Hour();

你会有这样一个工作时钟:

Image shows a working digital clock which matches system time

关于java - 我如何从文本时钟中获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36712949/

相关文章:

android - 为什么我无法构建 Android 源代码?

iphone - 如何重新排列 char* 中的字符?

c# - 连接数组中的字符串并包含它的索引 C#

java - 突出显示 JTextArea

java - 如何使用compareTo()方法比较List中的对象?

java - 我的 Java 纸牌游戏出现问题

android - Notification.Builder 添加 Action

android - 实际的 Android 布局与设计器不同

php - 使用 smarty 从字符串中去除空格

java - 了解执行器服务中的线程池大小