Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use from XML? #2

Closed
amigax opened this issue Oct 19, 2012 · 1 comment
Closed

How to use from XML? #2

amigax opened this issue Oct 19, 2012 · 1 comment

Comments

@amigax
Copy link

amigax commented Oct 19, 2012

Hey, programatically its working pretty good, but how do I load from XML? I tried this:

<com.qozix.map.MapView
    android:id="@+id/mymap"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
</com.qozix.map.MapView>

And the error:

java.lang.RuntimeException: Unable to resume activity {thrillseeker.app.paultons/thrillseeker.app.paultons.activities.ScrollingMapActivity}: android.view.InflateException: Binary XML file line #10: Error inflating class com.qozix.map.MapView
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2120)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2135)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1668)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class com.qozix.map.MapView
at android.view.LayoutInflater.createView(LayoutInflater.java:508)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.setContentView(ActionBarSherlockCompat.java:857)
at com.actionbarsherlock.app.SherlockActivity.setContentView(SherlockActivity.java:218)
at thrillseeker.app.paultons.activities.ScrollingMapActivity.onResumeX(ScrollingMapActivity.java:37)
at thrillseeker.app.silverputty.view.SilverActivity.onResume(SilverActivity.java:808)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1150)
at android.app.Activity.performResume(Activity.java:3832)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2110)
... 12 more
Caused by: java.lang.NoSuchMethodException: MapView(Context,AttributeSet)
at java.lang.Class.getMatchingConstructor(Class.java:643)
at java.lang.Class.getConstructor(Class.java:472)
at android.view.LayoutInflater.createView(LayoutInflater.java:480)
... 24 more

@moagrius
Copy link
Owner

It's currently not set up to inflate from XML. For a very basic implementation, you'd need to add a couple different signatures to the constructor... something like this might work (untested):

public MapView(Context context){
    super(context);
    setup();
}
public MapView(Context context, AttributeSet attrs) {
    super(context, attrs);
    setup();
}

public MapView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setup();
}

private void setup(){
    zoomManager = new ZoomManager();
    touchLayer = new TouchLayer(context);
    touchLayer.setGestureListener(touchLayerListener);
    addView(touchLayer);        
    tileLayer = new TileLayer(context);
    touchLayer.addLayer(tileLayer);     
    pathLayer = new PathLayer(context);
    touchLayer.addLayer(pathLayer);     
    markerLayer = new MarkerLayer(context);
    touchLayer.addLayer(markerLayer);
    requestUpdate();
}

I haven't implemented it fully since best practice would be to offer other options (tile size, patterns, etc), which isn't as straightforward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants