在Android中创建天文钟
我想知道如何在安卓系统中实现一个简单的计时器,带有一个开始和停止按钮,以HH:MM:SS:MsMs格式显示数据。。。我一直在搜索,我在谷歌开发者上找到了一些类,但他们没有给出例子,我迷路了。。。你能告诉我一个教程/例子吗?我刚开始使用Android:)任何帮助都将不胜感激。只需用XML或代码实现计时器,并使用其start()方法启动它,使用其stop()方法停止它 更多信息可在此处找到: XML:在Android中创建天文钟,android,implementation,chronometer,Android,Implementation,Chronometer,我想知道如何在安卓系统中实现一个简单的计时器,带有一个开始和停止按钮,以HH:MM:SS:MsMs格式显示数据。。。我一直在搜索,我在谷歌开发者上找到了一些类,但他们没有给出例子,我迷路了。。。你能告诉我一个教程/例子吗?我刚开始使用Android:)任何帮助都将不胜感激。只需用XML或代码实现计时器,并使用其start()方法启动它,使用其stop()方法停止它 更多信息可在此处找到: XML: 您可以在startChronometer()方法中添加一些代码来重新启动计数器。我有更多布局(XM
您可以在startChronometer()方法中添加一些代码来重新启动计数器。我有更多布局(XML),我想将计时器用于。。。我如何调整这一行“setContentView(R.layout.test);”,使其能够接收来自其他版面的调用,而不仅仅是来自“test”版面的调用?我不知道我是否理解正确,但是如果不在Java中添加计时表,那么在每个XML版面中都需要一个计时表,我有一个菜单,它将我重定向到五个相同的XML中的一个,带有一个计时器和一个java文件,java和XML都带有上面的代码。。。如何调整java文件以提供五个XML?或者我必须为每个xml创建一个java文件吗?如果xml总是相同的,那么您可以在每个菜单点上使用它。如果Java相同,请务必使用相同的Java。用你的菜单点开始同样的活动。但我不明白这有什么意义!好的,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>
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();
}
}