我使用的是從GitHub的mapviewballoons,它是工作到哪裏,我試圖從ballonItemizedOverlay加載活動從onBalloonTap
private ArrayList<OverlayItem> m_overlays = new ArrayList<OverlayItem>();
private Context c;
public mlgwItemizedOverlay(Drawable defaultMarker, MapView mapView) {
super(boundCenter(defaultMarker), mapView);
c = mapView.getContext();
}
public void addOverlay(OverlayItem overlay) {
m_overlays.add(overlay);
populate();
}
@Override
protected OverlayItem createItem(int i) {
return m_overlays.get(i);
}
@Override
public int size() {
return m_overlays.size();
}
@Override
protected boolean onBalloonTap(int index, OverlayItem item) {
Intent Details = new Intent(c, BlogActivity.class);
//Details.putExtra("Id", 1327);
c.startActivity(Details);
return true;
}
}
這裏是打開另一個活動點我主要活動
TapControlledMapView mapView; // use the custom TapControlledMapView
List<Overlay> mapOverlays;
Drawable drawable;
mlgwItemizedOverlay itemizedOverlay;
mlgwItemizedOverlay itemizedOverlay2;
private static final class LatLonPoints extends GeoPoint {
public LatLonPoints(double latitude, double longitude) {
super((int) (latitude * 1E6), (int) (longitude * 1E6));
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (TapControlledMapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
// dismiss balloon upon single tap of MapView (iOS behavior)
mapView.setOnSingleTapListener(new OnSingleTapListener() {
@Override
public boolean onSingleTap(MotionEvent e) {
itemizedOverlay.hideAllBalloons();
return true;
}
});
mapOverlays = mapView.getOverlays();
// first overlay
drawable = getResources().getDrawable(R.drawable.marker);
itemizedOverlay = new mlgwItemizedOverlay(drawable, mapView);
// set iOS behavior attributes for overlay
itemizedOverlay.setShowClose(false);
itemizedOverlay.setShowDisclosure(true);
itemizedOverlay.setSnapToCenter(false);
GeoPoint StartPoint = new LatLonPoints(35.149534,-90.04898);
// first overlay
GeoPoint point = new LatLonPoints(35.139646,-90.05521);
OverlayItem overlayItem = new OverlayItem(point, "Hello", "I'm am the first location");
itemizedOverlay.addOverlay(overlayItem);
mapOverlays.add(itemizedOverlay);
GeoPoint point2 = new LatLonPoints(35.020922,-90.027045);
OverlayItem overlayItem2 = new OverlayItem(point2, "Hello", "I'm am the second location");
itemizedOverlay.addOverlay(overlayItem2);
mapOverlays.add(itemizedOverlay);
GeoPoint point3 = new LatLonPoints(35.151009,-89.978281);
OverlayItem overlayItem3 = new OverlayItem(point3, "Hello", "I'm am the third location");
itemizedOverlay.addOverlay(overlayItem3);
mapOverlays.add(itemizedOverlay);
GeoPoint point4 = new LatLonPoints(35.088971,-89.965608);
OverlayItem overlayItem4 = new OverlayItem(point4, "Hello", "I'm am the fourth location");
itemizedOverlay.addOverlay(overlayItem4);
mapOverlays.add(itemizedOverlay);
GeoPoint point5 = new LatLonPoints(35.341282,-89.8922298);
OverlayItem overlayItem5 = new OverlayItem(point5, "Hello", "I'm am the fifth location");
itemizedOverlay.addOverlay(overlayItem5);
mapOverlays.add(itemizedOverlay);
if (savedInstanceState == null) {
final MapController mc = mapView.getController();
mc.animateTo(StartPoint);
mc.setZoom(11);
} else {
// example restoring focused state of overlays
int focused;
focused = savedInstanceState.getInt("focused_1", -1);
if (focused >= 0) {
itemizedOverlay.setFocus(itemizedOverlay.getItem(focused));
}
focused = savedInstanceState.getInt("focused_2", -1);
if (focused >= 0) {
itemizedOverlay2.setFocus(itemizedOverlay2.getItem(focused));
}
}
}
public void startCustomActivity(){
Intent Details = new Intent(getBaseContext(), BlogActivity.class);
Details.putExtra("Id", 1327);
startActivity(Details);
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
@Override
protected void onSaveInstanceState(Bundle outState) {
// example saving focused state of overlays
if (itemizedOverlay.getFocus() != null) outState.putInt("focused_1", itemizedOverlay.getLastFocusedIndex());
if (itemizedOverlay2.getFocus() != null) outState.putInt("focused_2", itemizedOverlay2.getLastFocusedIndex());
super.onSaveInstanceState(outState);
}
}
,這裏是博客活動我試圖打開
public class BlogActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textview = new TextView(this);
textview.setText("This is the Blog tab");
setContentView(textview);
}
}
一旦我按覆蓋應用程序崩潰和正在返回的錯誤是:
04-18 04:39:56.465: E/MapActivity(8938): Couldn't get connection factory client 04-18 04:40:03.075: E/AndroidRuntime(8938): FATAL EXCEPTION: main 04-18 04:40:03.075: E/AndroidRuntime(8938): java.lang.RuntimeException: Unable to pause activity {com.mlgw.MlgwMapView/com.mlgw.MlgwMapView.MlgwMapViewActivity}: java.lang.NullPointerException 04-18 04:40:03.075: E/AndroidRuntime(8938): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2354) 04-18 04:40:03.075: E/AndroidRuntime(8938): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2311) 04-18 04:40:03.075: E/AndroidRuntime(8938): at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:2291) 04-18 04:40:03.075: E/AndroidRuntime(8938): at android.app.ActivityThread.access$1700(ActivityThread.java:117) 04-18 04:40:03.075: E/AndroidRuntime(8938): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:938) 04-18 04:40:03.075: E/AndroidRuntime(8938): at android.os.Handler.dispatchMessage(Handler.java:99) 04-18 04:40:03.075: E/AndroidRuntime(8938): at android.os.Looper.loop(Looper.java:130) 04-18 04:40:03.075: E/AndroidRuntime(8938): at android.app.ActivityThread.main(ActivityThread.java:3683) 04-18 04:40:03.075: E/AndroidRuntime(8938): at java.lang.reflect.Method.invokeNative(Native Method) 04-18 04:40:03.075: E/AndroidRuntime(8938): at java.lang.reflect.Method.invoke(Method.java:507) 04-18 04:40:03.075: E/AndroidRuntime(8938): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 04-18 04:40:03.075: E/AndroidRuntime(8938): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 04-18 04:40:03.075: E/AndroidRuntime(8938): at dalvik.system.NativeStart.main(Native Method) 04-18 04:40:03.075: E/AndroidRuntime(8938): Caused by: java.lang.NullPointerException 04-18 04:40:03.075: E/AndroidRuntime(8938): at com.mlgw.MlgwMapView.MlgwMapViewActivity.onSaveInstanceState(MlgwMapViewActivity.java:131) 04-18 04:40:03.075: E/AndroidRuntime(8938): at android.app.Activity.performSaveInstanceState(Activity.java:1037) 04-18 04:40:03.075: E/AndroidRuntime(8938): at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1181) 04-18 04:40:03.075: E/AndroidRuntime(8938): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2336) 04-18 04:40:03.075: E/AndroidRuntime(8938): ... 12 more
我的主要目標是通過更有關他們點擊新活動的註釋的數據。
你能告訴我我做錯了什麼或指向正確的解決方案。我搜索谷歌的其他答案,但我還沒有找到任何工作。
** ** MapViewActivity已經**的onPause()**方法重寫..? – ngesh 2012-04-18 04:58:31
沒有onPause()在主要活動 – UndercoverGeek 2012-04-18 05:07:25
非常有幫助http://stackoverflow.com/a/12816717/2183972 它解決了動作監聽器在ballon – Daniel 2013-04-29 20:59:44