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