Issue
I wanted to use a MapView inside a scrollView . doing so will cause scroll problem for your map and when you want to scroll the map the entire page will get scrolled . I found a solution for this problem here : MapView inside a ScrollView?
I created a class named myMapView . here's it's code :
package com.wikitude.example;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import com.google.android.maps.MapView;
public class myMapView extends MapView {
public myMapView(Context context, String apiKey) {
super(context, apiKey);
// TODO Auto-generated constructor stub
}
public myMapView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public myMapView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
int action = ev.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
// Disallow ScrollView to intercept touch events.
this.getParent().requestDisallowInterceptTouchEvent(true);
break;
case MotionEvent.ACTION_UP:
// Allow ScrollView to intercept touch events.
this.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
// Handle MapView's touch events.
super.onTouchEvent(ev);
return false;
}
}
but when I try to use it in my MapActivity like this :
myMapView myview = (myMapView) findViewById(R.id.themap);
it throws this error :
Undable to start activity ComponentInfo{com.smtabatabaie.example/com.smtabatabaie.mainActivity}: java.lang.ClassCastException: com.google.android.maps.MapView
.
I didn't find where the problem is , seems everything's alright . I'll be appreciated if someone can help me with this
thanks
Solution
Here's why you're getting that ClassCastException. In your XML file where you declare the custom mapview you have to actually declare the name of your custom mapview so in your case it would be myMapView. This is what your XML file should look like:
<com.wikitude.example.myMapView //This is where you're probably going wrong (so what I've posted is the right way to declare it)
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapview"
android:layout_width="fill_parent" //Replace these with whatever width and height you need
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="Enter-your-key-here"
/>
Answered By - Vishwa Patel
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.