2013-02-20 121 views
2

我实现了一个InfoWindowAdapter返回该充气XML谷歌地图信息窗口阻止点击事件

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:id="@+id/layoutRoot" 
    android:clickable="true"> 

    <TextView 
     android:id="@+id/titleText" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:text="Medium Text" 
     android:textStyle="bold" 
     android:textAppearance="?android:attr/textAppearanceMedium" /> 

    <TextView 
     android:id="@+id/snippetText" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Medium Text" 
     android:gravity="center" 
     android:textAppearance="?android:attr/textAppearanceMedium" /> 

</LinearLayout> 

这是由

public class MarkerWindowProvider implements InfoWindowAdapter { 
    private LayoutInflater lInflater; 
    private InfoWindowClickListener onClick; 

    public MarkerWindowProvider(Context parent, InfoWindowClickListener onClick) { 
     lInflater = (LayoutInflater) parent.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     this.onClick = onClick; 
    } 

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

    @Override 
    public View getInfoWindow(final Marker marker) { 
     View contents = lInflater.inflate(R.layout.custom_infowindow, null); 
     ((TextView)contents.findViewById(R.id.titleText)).setText(marker.getTitle()); 
     ((TextView)contents.findViewById(R.id.snippetText)).setText(marker.getTitle()); 
     contents.setOnClickListener(new OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       onClick.onClick(marker); 
      } 
     }); 
     return contents; 
    } 

    public interface InfoWindowClickListener { 
     public void onClick(Marker marker); 
    } 
} 

膨胀的布局显示,而不是股票信息窗口,但膨胀无论我选择哪种方法将XML充入XML,OnClick方法都不会触发。

我真的需要这个功能。任何想法,为什么这不工作?任何替代品? 谢谢。

回答

0

据说,你不能在信息窗口内处理来自视图的任何事件。此弹出窗口不是“实时”视图,您甚至无法禁用默认背景选择器(以阻止闪烁)。不幸。 所以不建议将按钮和文本视图用于输入。