0

I have a relative layout to show a menu with some buttons and edittext. This is displayed fine. When I add a listview to a parent relative layout (to display the listview below the menu layout), but the listview is not shown. My XML code is inserted below.

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.MapFragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <RelativeLayout
        android:id="@+id/listactivity"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

    <RelativeLayout
        android:id="@+id/menu"
        android:layout_width="match_parent"
        android:layout_height="75dp"
        android:background="#ff0000"
        android:orientation="vertical"
        android:focusableInTouchMode="true" 
        android:layout_gravity="top" >

        <Button
            android:id="@+id/cities"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Cities"
            android:textStyle="bold"
            android:onClick="showPopup" />

    <Button
        android:id="@+id/addcity"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:minWidth="30dp"
        android:text="+"
        android:textStyle="bold"
        android:layout_toRightOf="@+id/cities" />

    <Button
        android:id="@+id/days"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Days"
        android:textStyle="bold"
        android:layout_toRightOf="@+id/addcity" />

    <Button
        android:id="@+id/addday"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/days"
        android:minWidth="30dp"
        android:text="+"
        android:textStyle="bold" />

    <Button
        android:id="@+id/Days"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text=""
        android:layout_toRightOf="@+id/addday"
        android:textStyle="bold"
        android:onClick="showListview" />

    <EditText
        android:id="@+id/myEditText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_below="@+id/cities"
        android:ems="10" >
    </EditText>

</RelativeLayout>

    <ListView
        android:id="@+id/listview"
        android:background="#fff000"
        android:layout_width="150dp"
        android:layout_height="wrap_content"
        android:visibility="visible"
        android:layout_below="@+id/menu" />

</RelativeLayout>

NiAu
  • 535
  • 1
  • 12
  • 32
  • please please PLEASE format your code before pasting it here. Both eclipse and Android studio have automatic formatting functions that work perfectly for XML. – paul Aug 26 '14 at 16:16
  • Simple question: Does your ListView contain rows to show? So is there data to display? – reVerse Aug 26 '14 at 16:20

2 Answers2

1

It might be because your list view has a height set of wrap_content you should avoid using this for lists. Try setting it to a specific height and see if that helps

Here is a link to a good answer about this https://stackoverflow.com/a/4271930/1417483

Community
  • 1
  • 1
Dreagen
  • 1,733
  • 16
  • 21
0

Because the ListView's height is set to wrap_content, it will have a height of 0dp until you add something to it.

Make sure you initialise the ListView and add some dummy data to it. The other option is to set the ListView height to stretch to the bottom of the screen like this:

    <ListView
        android:id="@+id/listview"
        android:background="#fff000"
        android:layout_width="150dp"
        android:layout_height="0dp"
        android:visibility="visible"
        android:layout_below="@+id/menu"
        android:layout_alignParentBottom="true"/>
paul
  • 1,193
  • 8
  • 11