Skip to content Skip to sidebar Skip to footer

Why Touch Not Work On Google Map V2?

I am working on Google Maps v2. I need to do some stuff on map touch, but I'm unable to get touch listener of Google Maps v2. I am inflating XML which contains fragment XML. My c

Solution 1:

I change My xml as:-

 <fragment
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"class="com.fd.viewhelper.MapViewHelper"
        />

Here com.fd.viewhelper.MapViewHelper, is class name which extends SupportMapFragment and override its method,here running code of that class:-

package com.fd.viewhelper;


publicclassMapViewHelperextendsSupportMapFragment {

    private FragmentActivity objactivity;
    publicGoogleMapmyMap=null;
    private FlashDeaOverlay itemizedoverlay;
    private List<GroupDealModle> objgroupdeallist;
    private ArrayList<FlashDeaOverlay> objflashdealoverlay = newArrayList<FlashDeaOverlay>();
    private Bitmap objbitmap;
    privatedoublelat=0, lng = 0;
    private Context objcontext;

    publicMapViewHelper()
    {
    }
    publicMapViewHelper(FragmentActivity objactivity) {
        this.objactivity = objactivity;
    }

    /*
     * @return view of map
     * 
     * @author Sandeep Tiwari
     */public View getMapView() {
        ViewobjView= View.inflate(objactivity, R.layout.homemapview, null);
        return objView;
    }

    public GoogleMap InstantiateMapView() {
        if (myMap == null) {
            // Try to obtain the map from the SupportMapFragment.
            myMap = ((SupportMapFragment) this.objactivity
                    .getSupportFragmentManager().findFragmentById(R.id.map))
                    .getMap();
        }
        return myMap;
    }



    public View mOriginalContentView;
    public TouchableWrapper mTouchView;

    @Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup parent,
            Bundle savedInstanceState) {
        mOriginalContentView = super.onCreateView(inflater, parent,
                savedInstanceState);
        mTouchView = newTouchableWrapper(getActivity());
        mTouchView.addView(mOriginalContentView);
        return mTouchView;
    }

    @Overridepublic View getView() {
        return mOriginalContentView;
    }

    publicclassTouchableWrapperextendsFrameLayout {

        publicTouchableWrapper(Context context) {
            super(context);
            objcontext = context;
        }

        @OverridepublicbooleandispatchTouchEvent(MotionEvent ev) {
            switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                ((MainActivity) objcontext).MotionDown(ev);
                break;

            case MotionEvent.ACTION_POINTER_DOWN:
                ((MainActivity) objcontext).MotionPointerDown(ev);
                break;

            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_POINTER_UP:
                ((MainActivity) objcontext).MotionUp(ev);
                break;

            case MotionEvent.ACTION_MOVE:
                ((MainActivity) objcontext).ActionMove(ev);
                break;

            }
            returnsuper.dispatchTouchEvent(ev);
        }
    }

    // Map Activity must implement this interfacepublicinterfaceUpdateMapAfterUserInterection {
        publicvoidonUpdateMapAfterUserInterection();
    }
}

Post a Comment for "Why Touch Not Work On Google Map V2?"