Prevent Listview links from being intercepted using its Child MapView

I want to prevent Listview links from being intercepted during navigation, scaling, and compression in MapView, which is inside the Listview's list header.

I have one ListView containing all the stores. I set one list header as another xml layout and adding it to the Main ListView.

ListView List Title

<com.google.android.gms.maps.MapView
    android:id="@+id/mapViewStores"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:layout_margin="10dp" />

StoreList.java that extends Fragment

MapView mapView;        //Map View
GoogleMap mapStoreList; //For Markers on Map

listViewStoreData.addHeaderView(headerViewForStoreList);

mapView = (MapView) headerViewForStoreList
                .findViewById(R.id.mapViewStores);
        mapView.onCreate(savedInstanceState);

if (mapView != null) {
    mapStoreList = mapView.getMap();
    mapStoreList.getUiSettings().setMyLocationButtonEnabled(true);
    mapStoreList.setMyLocationEnabled(true);
    CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(
                    new LatLng(latitude, longitude), 13);
    mapStoreList.animateCamera(cameraUpdate);
}

I set the prohibition code to intercept the strokes of the parent view

mapStoreList.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {

            switch (event.getAction()) {

            case MotionEvent.ACTION_UP:
                this.getParent().requestDisallowInterceptTouchEvent(false);
                break;

            case MotionEvent.ACTION_DOWN:
                this.getParent().requestDisallowInterceptTouchEvent(true);
                break
            }

            return super.onTouchEvent(ev);
        }
    });

Unfortunately, it does not work.

But when you install an object OnTouchListenerin ListViewit, it will log events.

listViewStoreData.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {

            switch (event.getAction()) {
            case MotionEvent.ACTION_MOVE:
                Log.e("MotionEvent", "Move");
                break;

            case MotionEvent.ACTION_UP:
                Log.e("MotionEvent", "Up");
                break;

            case MotionEvent.ACTION_DOWN:
                Log.e("MotionEvent", "Down");
                break;

            case MotionEvent.ACTION_CANCEL:
                Log.e("MotionEvent", "Cancel");
                break;

            case MotionEvent.ACTION_POINTER_INDEX_MASK:
                Log.e("MotionEvent", "Pointer Index Mask");
                break;

            case MotionEvent.ACTION_POINTER_INDEX_SHIFT:
                Log.e("MotionEvent", "Pointer Index Shift");
                break;
            }

            return false;
        }
    });

, ?
, 'OnTouchListerner' ListView → Child → MapView??

.

+4
1

dispatchTouchEvent() ACTION_DOWN. ViewGroup, MapView, , , , MapView. , , ListView, MapView.

@Override
public boolean dispatchTouchEvent(final MotionEvent motionEvent) {

    switch (motionEvent.getActionMasked()) {
        // Pressed on map: stop listview from scrolling
        case MotionEvent.ACTION_DOWN:
            listView.requestDisallowInterceptTouchEvent(true);
            break;

        // Released on map or cancelled: listview can be normal again
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_CANCEL:
            listView.requestDisallowInterceptTouchEvent(false);
            break;
    }

    // Process event as normal. If listview was disallowed touch events, the map will process the event.
    return super.dispatchTouchEvent(motionEvent);
}

, , / , .

+4

Source: https://habr.com/ru/post/1535313/


All Articles