Reputation: 31
I have been trying to implement a ListView inside a custom Google maps info window.
How do I get the ListView to populate and show?
I have the info window showing with the other relevant information by creating this InfoWindowAdapter
class CustomInfoWindowAdapter implements InfoWindowAdapter {
@Override
public View getInfoContents(Marker arg0) {
// Getting view from the layout file info_window_layout
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
View v = (View)inflater.inflate(R.layout.custom_info_window, null);
if (clickedClusterItem != null) {
//This is the area that does not show
ListView listitemview = (ListView) v.findViewById(R.id.ListItems);
InfoItemAdapter customadapter = new InfoItemAdapter(MapActivity.this,clickedClusterItem.ListItems);
listitemview.setAdapter(customadapter);
//Getting reference to the TextView to set footer
TextView footer = (TextView) v.findViewById(R.id.InfoFooter);
footer.setText(getResources().getString(R.string.info_window_footer));
//Getting reference to the TextView to set Title
TextView name = (TextView) v.findViewById(R.id.LocationName);
name.setText(clickedClusterItem.Name);
}
// Returning the view containing InfoWindow contents
return v;
}
@Override
public View getInfoWindow(Marker arg0) {
// TODO Auto-generated method stub
return null;
}
}
The Custom adapter for each item in the list
public class InfoItemAdapter extends ArrayAdapter<ListItem> {
private final Context context;
private final ArrayList<ListItem> listitems;
public InfoItemAdapter(Context context, ArrayList<ListItem> listitems) {
super(context, R.layout.custom_info_window_list_item);
this.context = context;
this.listitems= listitems;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.custom_info_window_list_item, parent, false);
TextView firstLine = (TextView) rowView.findViewById(R.id.firstLine);
firstLine.setText(listitems.get(position).getDescription());
TextView secondLine = (TextView) rowView.findViewById(R.id.secondLine);
secondLine.setText(listitems.get(position).getTimeString());
// Set the icon
ImageView imageView = (ImageView) rowView.findViewById(R.id.icon);
imageView.setImageResource(listitems.get(position).getIcon());
return rowView;
}
}
These are my XML layouts
The parent view which contains the List and other properties which are populated
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/LocationName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
android:textSize="20sp"
android:textColor="#4e0e79" />
<ListView
android:id="@+id/ListItems"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_below="@+id/LocationName">
</ListView>
<TextView
android:id="@+id/InfoFooter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
android:textSize="16sp"
android:text="@string/info_window_footer" />
</RelativeLayout>
List Item
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip" >
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_marginRight="6dip"
android:contentDescription="@string/icon_desc"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/secondLine"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_toRightOf="@id/icon"
android:ellipsize="marquee"
android:singleLine="true"
android:textSize="12sp" />
<TextView
android:id="@+id/firstLine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@id/secondLine"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_alignWithParentIfMissing="true"
android:layout_toRightOf="@id/icon"
android:gravity="center_vertical"
android:textSize="16sp" />
</RelativeLayout>
This poster seems to have accomplished it but I cant seem to get it to work. I do not need click functionality on the list android marker custom infowindow
Upvotes: 1
Views: 1581
Reputation: 31
OK, I could not get the list to populate within the info window.
I ended up getting my desired result by building the new views programatically within the CustomInfoWindowAdapter -> getInfoContents method.
This is my updated CustomInfoWindowClass which does work. If anyone comes across this who knows how to implement a list on a info window your input would be appreciated.
class CustomInfoWindowAdapter implements InfoWindowAdapter {
@Override
public View getInfoContents(Marker arg0) {
// Getting view from the layout file info_window_layout
LayoutInflater inflater = (LayoutInflater) MapActivity.this.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
View v = (View)inflater.inflate(R.layout.custom_info_window, null);
LinearLayout view = (LinearLayout)v;
if (clickedClusterItem != null) {
if(clickedClusterItem.ListItems.size()>0){
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(10, 0, 10, 0);
for(ListItem listItem : clickedClusterItem.ListItems){
TextView listitemdesc = new TextView(MapActivity.this);
TextView listitemtime = new TextView(MapActivity.this);
listitemdesc.setText(hh.getDescription());
listitemdesc.setTextSize(18f);
listitemtime.setTextSize(12f);
listitemtime.setText(hh.getTimeString());
if(Helpers.isActive(listItem))
{
listitemdesc.setTextColor(Color.parseColor("#f7941d"));
listitemtime.setTextColor(Color.parseColor("#f7941d"));
}
else if(Helpers.isCommingSoon(listItem)){
listitemdesc.setTextColor(Color.parseColor("#008fd5"));
listitemtime.setTextColor(Color.parseColor("#008fd5"));
}
else{
listitemdesc.setTextColor(Color.parseColor("#515e64"));
}
listitemdesc.setLayoutParams(lp);
listitemtime.setLayoutParams(lp);
view.addView(listitemdesc);
view.addView(listitemtime);
}
}
//Getting reference to the TextView to set Title
TextView name = (TextView) v.findViewById(R.id.LocationName);
name.setText(clickedClusterItem.Name);
}
// Returning the view containing InfoWindow contents
return v;
}
@Override
public View getInfoWindow(Marker arg0) {
// TODO Auto-generated method stub
return null;
}
}
Upvotes: 1