我正在使用此链接:https://stackoverflow.com/a/10585401/3176433为 OSMdroid 覆盖ItemizedIconOverlay。不幸的是,每当我触发SingleTap时,应用程序都会崩溃。
幸运的是,如果我按照这样覆盖:https://stackoverflow.com/a/20441999/3176433 应用不会崩溃。但我不想这样做。
因为我无法访问我为ItemizedIconOverlay类传递的手势监听器。我无法覆盖
new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() {
@Override
public boolean onItemSingleTapUp(int index, OverlayItem item) {
Log.d("APP","HERE");
//Control Doesn't Come here
return true;
}
@Override
public boolean onItemLongPress(int index, OverlayItem item) {
return true;
}
请告诉我一个可以覆盖onItemSingleTapUp的可能解决方案? 我确实关注了相关链接:OSMDroid crashes when zooming out,Adding ItemizedOverlay to my mapview,Android ItemizedOverlay<OverlayItem> issue
但是并没有完全理解。 的修改 这是我的堆栈跟踪:
04-10 09:41:24.280: I/Adreno-EGL(9402): <qeglDrvAPI_eglInitialize:320>: EGL 1.4 QUALCOMM Build: I0404c4692afb8623f95c43aeb6d5e13ed4b30ddbDate: 11/06/13
04-10 09:41:24.300: D/OpenGLRenderer(9402): Enabling debug mode 0
04-10 09:41:27.493: D/dalvikvm(9402): GC_FOR_ALLOC freed 99K, 2% free 9394K/9524K, paused 18ms, total 20ms
04-10 09:41:27.603: I/org.osmdroid.views.MapView(9402): Using tile source: org.osmdroid.tileprovider.tilesource.XYTileSource@41ed03b8
04-10 09:41:27.613: I/org.osmdroid.tileprovider.modules.MapTileFileStorageProviderBase(9402): sdcard state: mounted
04-10 09:41:27.613: I/org.osmdroid.tileprovider.modules.MapTileFileStorageProviderBase(9402): sdcard state: mounted
04-10 09:41:27.653: D/dalvikvm(9402): GC_FOR_ALLOC freed 226K, 3% free 9682K/9940K, paused 15ms, total 15ms
04-10 09:41:27.733: D/dalvikvm(9402): GC_FOR_ALLOC freed 163K, 2% free 10025K/10228K, paused 18ms, total 18ms
04-10 09:41:27.783: D/dalvikvm(9402): GC_FOR_ALLOC freed 37K, 2% free 10394K/10560K, paused 19ms, total 19ms
04-10 09:41:27.803: I/org.osmdroid.tileprovider.MapTileProviderBase(9402): rescale tile cache from 0 to 5
04-10 09:41:27.813: I/org.osmdroid.tileprovider.MapTileProviderBase(9402): Finished rescale in 4ms
04-10 09:41:27.853: D/dalvikvm(9402): GC_FOR_ALLOC freed 84K, 2% free 10819K/10940K, paused 20ms, total 20ms
04-10 09:41:27.903: D/dalvikvm(9402): GC_FOR_ALLOC freed 367K, 4% free 11043K/11460K, paused 20ms, total 20ms
04-10 09:41:28.043: D/dalvikvm(9402): GC_FOR_ALLOC freed 346K, 4% free 11386K/11764K, paused 23ms, total 23ms
04-10 09:41:28.113: I/SensorManager(9402): This application is using deprecated SensorManager API which will be removed someday. Please consider switching to the new API.
04-10 09:41:28.244: I/org.osmdroid.tileprovider.LRUMapTileCache(9402): Tile cache increased from 9 to 63
04-10 09:41:28.264: D/dalvikvm(9402): GC_FOR_ALLOC freed 407K, 4% free 11776K/12216K, paused 26ms, total 27ms
04-10 09:41:28.344: D/dalvikvm(9402): GC_FOR_ALLOC freed 128K, 4% free 12336K/12736K, paused 22ms, total 22ms
04-10 09:41:28.374: D/dalvikvm(9402): GC_FOR_ALLOC freed 1K, 3% free 12882K/13256K, paused 23ms, total 26ms
04-10 09:41:28.444: D/dalvikvm(9402): GC_FOR_ALLOC freed 73K, 3% free 13676K/14036K, paused 43ms, total 43ms
04-10 09:41:28.484: D/dalvikvm(9402): GC_FOR_ALLOC freed 86K, 3% free 14688K/15076K, paused 30ms, total 30ms
04-10 09:41:28.574: D/dalvikvm(9402): GC_FOR_ALLOC freed 600K, 5% free 15621K/16368K, paused 27ms, total 27ms
04-10 09:41:28.804: D/dalvikvm(9402): GC_FOR_ALLOC freed 1469K, 9% free 16333K/17836K, paused 26ms, total 26ms
04-10 09:41:29.054: D/dalvikvm(9402): GC_FOR_ALLOC freed 2455K, 14% free 16334K/18820K, paused 31ms, total 31ms
04-10 09:41:29.335: D/dalvikvm(9402): GC_FOR_ALLOC freed 2484K, 14% free 16303K/18820K, paused 30ms, total 30ms
04-10 09:41:29.605: D/dalvikvm(9402): GC_FOR_ALLOC freed 2446K, 14% free 16300K/18820K, paused 29ms, total 29ms
04-10 09:41:29.875: D/dalvikvm(9402): GC_FOR_ALLOC freed 2319K, 13% free 16382K/18820K, paused 28ms, total 28ms
04-10 09:41:30.145: D/dalvikvm(9402): GC_FOR_ALLOC freed 2077K, 13% free 16382K/18820K, paused 25ms, total 25ms
04-10 09:41:30.486: D/dalvikvm(9402): GC_FOR_ALLOC freed 2298K, 13% free 16383K/18820K, paused 25ms, total 25ms
04-10 09:41:30.806: D/dalvikvm(9402): GC_FOR_ALLOC freed 2443K, 14% free 16295K/18820K, paused 31ms, total 31ms
04-10 09:41:31.146: D/dalvikvm(9402): GC_FOR_ALLOC freed 2340K, 14% free 16319K/18820K, paused 28ms, total 28ms
04-10 09:41:31.317: D/AndroidRuntime(9402): Shutting down VM
04-10 09:41:31.317: W/dalvikvm(9402): threadid=1: thread exiting with uncaught exception (group=0x41548ba8)
04-10 09:41:31.317: E/AndroidRuntime(9402): FATAL EXCEPTION: main
04-10 09:41:31.317: E/AndroidRuntime(9402): Process: com.cassidian.tasp, PID: 9402
04-10 09:41:31.317: E/AndroidRuntime(9402): java.lang.NullPointerException
04-10 09:41:31.317: E/AndroidRuntime(9402): at org.osmdroid.views.overlay.ItemizedIconOverlay.activateSelectedItems(ItemizedIconOverlay.java:170)
04-10 09:41:31.317: E/AndroidRuntime(9402): at org.osmdroid.views.overlay.ItemizedIconOverlay.onSingleTapConfirmed(ItemizedIconOverlay.java:118)
04-10 09:41:31.317: E/AndroidRuntime(9402): at org.osmdroid.views.overlay.OverlayManager.onSingleTapConfirmed(OverlayManager.java:233)
04-10 09:41:31.317: E/AndroidRuntime(9402): at org.osmdroid.views.MapView$MapViewDoubleClickListener.onSingleTapConfirmed(MapView.java:1566)
04-10 09:41:31.317: E/AndroidRuntime(9402): at android.view.GestureDetector$GestureHandler.handleMessage(GestureDetector.java:273)
04-10 09:41:31.317: E/AndroidRuntime(9402): at android.os.Handler.dispatchMessage(Handler.java:102)
04-10 09:41:31.317: E/AndroidRuntime(9402): at android.os.Looper.loop(Looper.java:136)
04-10 09:41:31.317: E/AndroidRuntime(9402): at android.app.ActivityThread.main(ActivityThread.java:5017)
04-10 09:41:31.317: E/AndroidRuntime(9402): at java.lang.reflect.Method.invokeNative(Native Method)
04-10 09:41:31.317: E/AndroidRuntime(9402): at java.lang.reflect.Method.invoke(Method.java:515)
04-10 09:41:31.317: E/AndroidRuntime(9402): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
04-10 09:41:31.317: E/AndroidRuntime(9402): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
04-10 09:41:31.317: E/AndroidRuntime(9402): at dalvik.system.NativeStart.main(Native Method)
04-10 09:41:32.778: I/Process(9402): Sending signal. PID: 9402 SIG: 9
答案 0 :(得分:0)
通过互联网搜索我发现了这个问题的解决方案:打开你自己的itemizedOverlay。
class MyOwnItemizedOverlay extends ItemizedIconOverlay<OverlayItem> {
protected Context mContext;
public MyItemizedOverlay(final Context context, final List<OverlayItem> aList) {
super(context, aList, new OnItemGestureListener<OverlayItem>() {
@Override public boolean onItemSingleTapUp(final int index, final OverlayItem item) {
return false;
}
@Override public boolean onItemLongPress(final int index, final OverlayItem item) {
return false;
}
} );
mContext = context;
}
@Override protected boolean onSingleTapUpHelper(final int index, final OverlayItem item, final MapView mapView) {
//Toast.makeText(mContext, "Item " + index + " has been tapped!", Toast.LENGTH_SHORT).show();
AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
dialog.setTitle(item.getTitle());
dialog.setMessage(item.getSnippet());
dialog.show();
return true;
}
}
并在您的活动中使用它:
ArrayList<OverlayItem> list = new ArrayList<OverlayItem>();
MyOwnItemizedOverlay<OverlayItem> overlay = new MyOwnItemizedOverlay(this, list);
mapView.getOverlays.add(overlay);
你可以在这个问题的评论中找到这个例子: http://code.google.com/p/osmdroid/issues/detail?id=245