在mapview上的地图图像数据完成后,我应该在哪里编写代码来关闭ProgressDialog?
我在 setContentView 之后设置了 ProgressDialog 以弹出 ProgressDialog。
在地图视图上完成地图图像数据后,我想调用方法来关闭 ProgressDialog。
我想知道我应该在哪里编写代码来消除它。
我编写了这些源代码,如下所示。 如果您帮助我,我将非常感激。
谢谢。
这是我的地图活动类:
package sample.MyMap;
import sample.MyMap.R;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MyLocationOverlay;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
public class MyMapActivity extends MapActivity {
private MyMapView map;
private MapController controller;
private ProgressDialog progressDialog;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d("TEST", this + " onCreate");
setContentView(R.layout.main);
progressDialog = ProgressDialog.show(this, "Please wait...", "Loading map view ...", true);
initMapView();
initMyLocation();
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
private void initMapView() {
map = (MyMapView) findViewById(R.id.map);
controller = map.getController();
map.setSatellite(false);
map.setBuiltInZoomControls(true);
}
private void initMyLocation() {
final MyLocationOverlay overlay = new MyLocationOverlay(this, map);
overlay.enableMyLocation();
overlay.enableCompass();
overlay.runOnFirstFix(new Runnable() {
public void run() {
controller.setZoom(18);
controller.animateTo(overlay.getMyLocation());
}
});
map.getOverlays().add(overlay);
}
}
这是我的地图视图类:
package sample.MyMap;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import com.google.android.maps.MapView;
public class MyMapView extends MapView {
public MyMapView(Context context, String apiKey) {
super(context, apiKey);
}
public MyMapView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public MyMapView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
Log.d("TEST", "onDetachedFromWindow");
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
Log.d("TEST", "onSizeChanged");
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
Log.d("TEST", "onWindowFocusChanged");
}
@Override
public void preLoad() {
super.preLoad();
Log.d("TEST", "preLoad");
}
}
这是我的清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0" package="sample.MyMap">
<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:label="@string/app_name" android:name="MyMapActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<uses-library android:name="com.google.android.maps"></uses-library>
</application>
</manifest>
I set up ProgressDialog right after setContentView to pop ProgressDialog up.
After it's completed map image data on mapview, I wanna call method to dismiss ProgressDialog.
I wanna know where should I write the code to dismiss it.
I've written these source code as below.
I'm so appreciated if you help me.
Thank you.
Here is my map activity class:
package sample.MyMap;
import sample.MyMap.R;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MyLocationOverlay;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
public class MyMapActivity extends MapActivity {
private MyMapView map;
private MapController controller;
private ProgressDialog progressDialog;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d("TEST", this + " onCreate");
setContentView(R.layout.main);
progressDialog = ProgressDialog.show(this, "Please wait...", "Loading map view ...", true);
initMapView();
initMyLocation();
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
private void initMapView() {
map = (MyMapView) findViewById(R.id.map);
controller = map.getController();
map.setSatellite(false);
map.setBuiltInZoomControls(true);
}
private void initMyLocation() {
final MyLocationOverlay overlay = new MyLocationOverlay(this, map);
overlay.enableMyLocation();
overlay.enableCompass();
overlay.runOnFirstFix(new Runnable() {
public void run() {
controller.setZoom(18);
controller.animateTo(overlay.getMyLocation());
}
});
map.getOverlays().add(overlay);
}
}
Here is my mapview class:
package sample.MyMap;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import com.google.android.maps.MapView;
public class MyMapView extends MapView {
public MyMapView(Context context, String apiKey) {
super(context, apiKey);
}
public MyMapView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public MyMapView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
Log.d("TEST", "onDetachedFromWindow");
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
Log.d("TEST", "onSizeChanged");
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
Log.d("TEST", "onWindowFocusChanged");
}
@Override
public void preLoad() {
super.preLoad();
Log.d("TEST", "preLoad");
}
}
Here is my Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0" package="sample.MyMap">
<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:label="@string/app_name" android:name="MyMapActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<uses-library android:name="com.google.android.maps"></uses-library>
</application>
</manifest>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
把你的 initMapView & thraed 中的 initMyLocation 方法如下面的代码和描述:使用此方法后,将关闭对话框,如下定义
Put your initMapView & initMyLocation method in thraed as describe in below code & after this method dismiss the dialog as define below