繁体   English   中英

无法在InfoWindowAdapter中设置textview值

[英]Can't set textview value inside InfoWindowAdapter

我正在尝试使用以下代码创建自定义信息窗口。

内部活动:

mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
private final View contents = getLayoutInflater().inflate(R.layout.infowindow, null);

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

    @Override
    public View getInfoContents(Marker marker) {
        TextView txtTitle = ((TextView) contents.findViewById(R.id.txtInfoWindowTitle));
        txtTitle.setText("teste");
        return contents;
                    }
                });

为所有标记创建了信息窗口,并且布局文件正确,但是txtInfoWindowTitle始终为空,即使在infowindow.xml布局文件中定义了默认值也是如此

布局文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:gravity="center_vertical|center_horizontal">

        <TextView
            android:id="@+id/txtInfoWindowTitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:ellipsize="end"
            android:singleLine="true"
            android:textColor="#ff000000"
            android:textSize="14dp"
            android:textStyle="bold"
            android:text="primeira linha"
            android:gravity="center_vertical|center_horizontal" />

        <TextView

            android:id="@+id/txtInfoWindowClick"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ellipsize="end"
            android:singleLine="true"
            android:textColor="#ff7f7f7f"
            android:textSize="14dp"
            android:text="toque para abrir a ficha" />

</LinearLayout>

这段代码对我来说很好

View contents;

@Override
public View getInfoContents(Marker marker) {
    if(contents==null) {
        contents = getActivity().getLayoutInflater()
                .inflate(
                        R.layout.info_content,
                        null);
    }
    TextView txtTitle = (TextView) contents.findViewById(R.id.txtInfoWindowTitle);
    txtTitle.setText("teste");
        return contents;
    }

这是您在另一个布局中的LinearLayout吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM