我正在尝试实现自定义 MapView。在我的 MapActivity (名为 mainmap)中,我有一个扩展 MapView 的内部类:
private class Lmapview extends MapView{
public Lmapview(Context context, AttributeSet attrs) {
super(context, attrs);
gestures = new GestureDetector(mainmap.this, new GestureListener(this));
}
public boolean OnTouchEvent(MotionEvent event){
return gestures.onTouchEvent(event);
}
}
我将 main.xml 格式化为查找内部类,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<view
xmlns:android="http://schemas.android.com/apk/res/android"
class="com.mondo.tbuddy.mainmap$Lmapview"
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey=*****
/>
另外,在 Androidmanifest.xml 中,我有适当的<uses-library android:name="com.google.android.maps"/>
entry.
当我尝试运行我的应用程序时,我在 logcat 中得到(除其他外):
错误/AndroidRuntime(14999):引起
通过: android.view.InflateException:
二进制 XML 文件第 2 行:错误
膨胀类
com.mondo.tbuddy.mainmap$Lmapview
这是由我在 logcat 中找到的以下条目引起的:
错误/AndroidRuntime(14999):引起
通过:java.lang.NoSuchMethodException:
Lmapview(上下文,属性集)
如果我理解正确的话,我的应用程序正在崩溃,因为 Android 说它找不到适合我的自定义 MapView(Lmapview 类)的构造函数。然而,正如您在上面所看到的,它已被定义并且与它正在寻找的签名相匹配。
谁能给我一些见解吗?
Thanks.