在充气视图上禁用触摸

时间:2014-12-27 14:10:33

标签: android google-maps fragment marker android-inflate

我已经在GoogleMap上实现了InfoWindowAdapter,反对膨胀点击标记的视图,充气视图显示完美,但OnclickListener没有处理该视图的按钮,甚至没有触摸按钮。

实际情况是当我点击标记时,膨胀的视图出现在地图片段前面这可能是未触及或点击膨胀的视图的问题

以下是我的代码段

MainActivity.java

    setContentView(R.layout.activity_map_new);

    View view = findViewById(R.id.map);
    view.setEnabled(false);

    map = ((MapFragment) getFragmentManager()
            .findFragmentById(R.id.map)).getMap();
    map.getUiSettings().setZoomControlsEnabled(true);
    map.getUiSettings().setMyLocationButtonEnabled(true);   


    LatLng main = new LatLng(Double.parseDouble("31.5497"), Double.parseDouble("74.3436"));

    map.addMarker(new MarkerOptions()
    .title("Twitter")
    .snippet("tweet:")
    .position(main)
    .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_CYAN)));    

    map.setInfoWindowAdapter(new CustomMapAdaptor(getLayoutInflater().inflate(R.layout.activity_test, null)));

CustomMapAdaptor.java

public class CustomMapAdaptor  implements InfoWindowAdapter, OnClickListener {

private View view;
private Button btn1;

public CustomMapAdaptor(View v) {
    view = v;
}

@Override
public View getInfoContents(Marker marker) {

    btn1 = (Button) view.findViewById(R.id.btn1);
    Toast.makeText(view.getContext(), "getInfoContent call", Toast.LENGTH_SHORT).show();


    btn1.setOnClickListener(this);

    view.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            Toast.makeText(view.getContext(), "Bitches please i am touched", Toast.LENGTH_SHORT).show();
            return false;
        }
    });
     return view;
}

@Override
public View getInfoWindow(Marker marker) {
    return null;
}

@Override
public void onClick(View v) {
    Toast.makeText(view.getContext(), "Btn1 also clicked", Toast.LENGTH_SHORT).show();

}

}

1 个答案:

答案 0 :(得分:0)

尝试使用此设置您的监听器:

mMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener()