Raman Bhayana Raman Bhayana - 28 days ago 11
Android Question

Not able to show Map(fragment) in a list view

I want to show the map in a list view ,and for that I made a custom Layout shown below and calling it in a Adapter ,but the App crashes by giving :


A tag allows a layout file to dynamically include different
layouts at runtime. At layout editing time the specific layout to be
used is not known. You can choose which layout you would like
previewed while editing the layout.


Here is the XMl for custom Layout to be adapt in row of list view:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:paddingTop="10sp"
android:layout_height="match_parent">

<android.support.v7.widget.CardView
android:layout_width="match_parent"

android:id="@+id/card1"
android:layout_marginLeft="10sp"
android:layout_marginRight="10sp"
android:layout_below="@+id/sortButton"
android:layout_height="240sp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/map"

android:layout_width="match_parent"

android:layout_height="180sp"

class="com.google.android.gms.maps.SupportMapFragment"/>



<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="wrap_content"
android:layout_below="@+id/map"
android:src="@mipmap/ic_launcher"
android:id="@+id/circle"
android:layout_marginTop="5sp"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="wrap_content"
android:layout_toRightOf="@+id/circle"
android:layout_height="wrap_content"
android:id="@+id/times"
android:layout_below="@+id/map"
android:layout_marginTop="10sp"
android:text="Today at 1:04 PM"
android:textStyle="bold"/>

<TextView
android:layout_width="wrap_content"
android:layout_toRightOf="@+id/circle"
android:layout_height="wrap_content"
android:layout_below="@+id/times"
android:layout_marginTop="5sp"
android:textSize="15sp"
android:text="GreenPark,Delhi,India"
android:textStyle="bold"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:textStyle="bold"
android:layout_marginBottom="15sp"
android:layout_marginRight="5sp"
android:textSize="20sp"
android:text="$20"/>
</RelativeLayout>


</android.support.v7.widget.CardView>

</LinearLayout>

Answer

You can see the entire example at: https://github.com/vinirll/MapListView

In that case you would add the MapView to the list just like you would any other view. Here's a quick tutorial on how to create a custom list adapter. But I have to caution you, a MapView is a pretty heavy view and if you try to get a bunch of them on the screen you're going to notice the app being sluggish! You may just add a button to the list item that takes the user to another page with more information including a map.

Comments