我在我的主要活動如下代碼土司循環無法正常顯示
double latitude, longitude;
gps = new GPSTracker(MainActivity.this);
if(gps.canGetLocation()){
latitude = gps.getLatitude();
longitude = gps.getLongitude();
Toast.makeText(getApplicationContext(), "Your Location is - \nLat: " + latitude + "\nLong: " + longitude, Toast.LENGTH_LONG).show();
}
else{
gps.showSettingsAlert();
}
我想創建一個循環,這將在一定的時間間隔顯示Toast
與我目前的位置。從來就嘗試這樣做:
double latitude, longitude;
long currentTime = System.currentTimeMillis();
long myTimestamp = currentTime;
int i = 0;
gps = new GPSTracker(MainActivity.this);
while(i < 5)
{
myTimestamp = System.currentTimeMillis();
if((myTimestamp - currentTime) > 5000)
{
i++;
currentTime = System.currentTimeMillis();
if(gps.canGetLocation()){
latitude = gps.getLatitude();
longitude = gps.getLongitude();
Toast.makeText(getApplicationContext(), "Your Location is - \nLat: " + latitude + "\nLong: " + longitude, Toast.LENGTH_LONG).show();
}else{
gps.showSettingsAlert();
}
}
}
有了這個代碼,Toast
僅示出一個時間(最後迭代)。你能幫我解決這個問題嗎?提前致謝。
嘗試打印顯示的「I」舉杯 – nayab 2013-02-24 18:06:28
就像我說的,最後一次迭代過程中顯示吐司(I = 5) – Tom11 2013-02-24 18:08:20
雙檢查你的條件.. – moDev 2013-02-24 18:10:49