我想顯示自從活動在地圖數據視圖上開始以來的時間。Android定時器停止並開始
這是我正在使用的計時器代碼。我希望計時器在5分鐘後停止。我必須添加到此代碼才能使其工作?
package timer.tr;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handle;
import android.os.Handler;
import android.widget.TextView;
public class timer extends Activity {
private TextView timeView;
private int hour = 0;
private int min = 0;
private int sec = 0;
String mTimeFormat = "%02d:%02d:%02d";
final private Handler mHandler = new Handler();
Runnable mUpdateTime = new Runnable() {
public void run() { updateTimeView(); }
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
timeView = new TextView(this);
timeView.setText(String.format(mTimeFormat, hour, min, sec));
setContentView(timeView);
mHandler.postDelayed(mUpdateTime, 1000);
}
public void updateTimeView() {
sec += 1;
if(sec >= 60) {
sec = 0;
min += 1;
if (min >= 60) {
min = 0;
hour += 1;
}
}
timeView.setText(String.format(mTimeFormat, hour, min, sec));
mHandler.postDelayed(mUpdateTime, 1000);
}
}
這裏是我的佈局XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<com.google.android.maps.MapView
android:id="@+id/mapView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:enabled="true"
android:clickable="true"
android:apiKey="0cWhB29uXURimKWeF3lASx-MHSdekdEUZ1oZ-MQ"
/>
<RelativeLayout android:layout_height="wrap_content" android:id="@+id/relativeLayout1" android:layout_width="fill_parent"></RelativeLayout>
</LinearLayout>
目前,我再也看不到我的地圖視圖,我只看到我的TextView顯示的時間。
如何查看Google地圖中的計時器? – anji 2011-05-02 22:34:59
@koko您無法修改Google地圖。儘管您的活動可以使用「com.google.android.maps.MapView」向用戶顯示地圖。 – Jerome 2011-05-02 22:37:38
我將此代碼添加到已顯示地圖的我的項目中,但是當我添加此代碼時,地圖消失並且只有計數纔會出現,即使地圖中的疊加項消失 – anji 2011-05-02 22:42:17