单击android mapview中的覆盖弹出视图,同时单击窗口外部

时间:2013-02-21 10:18:20

标签: android

我正在使用带覆盖的mapview,在这里我选择覆盖项目,它显示特定覆盖项目的信息...现在我想在点击窗口侧面时关闭信息框.. 这里是我的示例代码..

popUp = getLayoutInflater().inflate(R.layout.village_popupwindow, null,
                false);
final GeoPoint selectedPoint = item.getPoint();     
mapParams = new MapView.LayoutParams(500, 300, selectedPoint,130, -200, MapView.LayoutParams.CENTER);
                mapView.addView(popUp, mapParams);

        ImageView imageView = (ImageView) findViewById(R.id.homeImage);
        TextView textTitle = (TextView) popUp.findViewById(R.id.text_title);
        TextView adress = (TextView) popUp.findViewById(R.id.text_plan);
        textTitle.setText(arrayListForAmenitiesDto.get(storeId).getName());
        adress.setText("Read more...");

任何人都知道如何解除这个弹出布局?没有在弹出布局中使用关闭按钮...我只想在popuplayout外部点击时忽略弹出布局。

3 个答案:

答案 0 :(得分:0)

您可以通过将 onTouchListener 注册到mapView来删除该弹出窗口。例如。

mapView.setOnTouchListener(new OnTouchListener() {          
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        try{
            //you can remove your popup here. hope this helps.
        }catch (Exception e) {}
      return false;
    }
});

答案 1 :(得分:0)

所有我修复了上述问题,我的回答是

otherHomesPlace.setOnFocusChangeListener(new OnFocusChangeListener() {

                @Override
                public void onFocusChanged(ItemizedOverlay overlay,
                        OverlayItem newFocus) {
                    // TODO Auto-generated method stub
                    System.out.println("Focus changed"+otherHomesPlace.getFocus());
                    if(otherHomesPlace.getFocus()==null){
                    popUp.setVisibility(View.GONE);
                }else{
                    popUp.setVisibility(View.VISIBLE);
                }
                }
            });

答案 2 :(得分:0)

只需使用此代码即可在外部触摸时关闭弹出窗口

    popUp.setOnTouchListener(new OnTouchListener() {            

        public boolean onTouch(View arg0, MotionEvent motionEvent) {

            return true;
        }
    });