创建于Android的天文台表 [英] Creating a chronometer in Android
问题描述
我想知道我怎么能在Android中实现简单的计时表以启动和停止按钮,在HH数据显示:MM:SS:MSMS格式...我一直在寻寻觅觅,我有发现谷歌开发了一些课程,但他们并没有给出例子,我迷路了......你能指点我一个教程/例子吗?我刚开始在Android的:)任何帮助将是非常美联社preciated。
I'd like to know how can I implement in Android a simple chronometer with a start and stop button that displays data in the HH:MM:SS:MsMs format... I've been searching and searching and I have found some classes on google developer, but they didn't give examples and I got lost... Could you direct me to a tutorial/example? I'm just starting out in Android :) Any help would be much appreciated.
推荐答案
只需实现天文台表在XML或code和使用它的start()方法来启动它和它的stop()方法来阻止它。
Just implement the Chronometer in XML or Code and use its start() method to start it and its stop() method to stop it.
更可以在这里找到:<一href="http://developer.android.com/reference/android/widget/Chronometer.html">http://developer.android.com/reference/android/widget/Chronometer.html
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Chronometer
android:id="@+id/chronometer1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start"
android:onClick="startChronometer"/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Stop"
android:onClick="stopChronometer"/>
</LinearLayout>
Java的:
Java:
public class Main extends FragmentActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
}
public void startChronometer(View view) {
((Chronometer) findViewById(R.id.chronometer1)).start();
}
public void stopChronometer(View view) {
((Chronometer) findViewById(R.id.chronometer1)).stop();
}
}
您可以添加一些code到startChronometer()方法来重新启动计数器。
You might add some code to the startChronometer() method to restart the counter.
这篇关于创建于Android的天文台表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!