我有一个空的ListView,它必须包含另外两个不同的ListViews,这取决于当我点击屏幕上的一个群集时GoogleMaps活动中群集中存在多少个标记,但是当我添加一个群集时我得到nullPointerException这个内部ListViews的主要部分。这两个日志显示正确的数据。这是代码:
java代码
public class myClusterInfoWindow implements GoogleMap.InfoWindowAdapter {
private View clusterView;
public myClusterInfoWindow () {
clusterView = getLayoutInflater().inflate(R.layout.cluster_info_window, null);
}
@Override
public View getInfoWindow(Marker marker) {
LinearLayout ll = (LinearLayout) findViewById(R.id.clusterll);
for (myClusterItem item : clickedCluster.getItems()) {
View portalView = getLayoutInflater().inflate(R.layout.portal_info_window, ll, true);
TextView title = (TextView) portalView.findViewById(R.id.name);
TextView hacks = (TextView) portalView.findViewById(R.id.hacks);
title.setText(item.getName());
hacks.setText(item.getHacks());
Log.d("CLUSTER", (String) title.getText());
Log.d("CLUSTER", (String) hacks.getText());
ll.addView(portalView); // TODO nullPointerException
}
return clusterView;
}
@Override
public View getInfoContents(Marker marker) {
return null;
}
}
cluster_info_window.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/clusterll">
</LinearLayout>
portal_info_window.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@color/wallet_bright_foreground_holo_light"
android:layout_marginBottom="5dp"
android:id="@+id/linearLayout">
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp" />
<TextView
android:id="@+id/hacks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"/>
</LinearLayout>
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New ToggleButton"
android:id="@+id/toggleButton"
android:layout_gravity="left|center_vertical"
android:layout_toRightOf="@+id/linearLayout"
android:background="@color/wallet_bright_foreground_holo_light"
android:layout_toEndOf="@+id/linearLayout"
android:layout_alignBottom="@+id/linearLayout"
android:layout_alignParentTop="true" />
</RelativeLayout>