0

I'm writing an application and have come across a bit of an issue. When working with a layout file, I have a 2 RelativeLayouts inside of a ViewFlipper.

The idea is that this page in particular is a welcome screen. The first RelativeLayout "welcomes" you to the app, and upon pushing a button, the user is led to the second RelativeLayout. In this layout there is a search bar that will allow the user to search for a certain criteria (specific to the app, not important) then display the results in a ListView.

Everything works correctly, but displaying the ListView seems to have some problems. The adapter is set properly, and I tested the method on another ListView in a test layout, and it worked fine. However something seems wrong with the ListView in the RelativeLayout. Here is the layout code

activity_welcome.xml

<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/welcomeFlipper"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:animateLayoutChanges="true"
    android:background="@color/white"
    tools:context="com.jacemcpherson.announcer.WelcomeActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white"
        android:padding="40dp">

        ...
        <!-- This code irrelevant, all's well :) -->

    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:animateLayoutChanges="true"
        android:background="@color/white"
        android:padding="40dp">

        <TextView
            android:id="@+id/textFirstThingsFirst"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@+id/textYouNeedToSearch"
            android:layout_centerHorizontal="true"
            android:text="@string/first_things_first"
            android:textColor="@color/app_color"
            android:textSize="32sp" />

        <TextView
            android:id="@+id/textYouNeedToSearch"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:layout_margin="10dp"
            android:gravity="center"
            android:text="@string/you_need_to_search_for_your_school"
            android:textColor="@color/black"
            android:textSize="18sp" />

        <EditText
            android:id="@+id/schoolSearchEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/textYouNeedToSearch"
            android:hint="@string/search_hint" />


        <ProgressBar
            android:id="@+id/searchListProgressBar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/schoolSearchEditText"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="20dp"
            android:visibility="gone" />

        <!-- This is the problem area -->
        <ListView
            android:id="@+id/searchResultsList"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/schoolSearchEditText" />

    </RelativeLayout>
</ViewFlipper>

I'm setting the adapter works like normal, but just in case I missed something, here's the line of code for that...

mListView.setAdapter(new ArrayAdapter<String>(
    mContext,
    android.R.layout.simple_list_item_1,
    result     // this is the array of results to be displayed in the list.
));

Thank you for your help, if I've missed something that in some way makes this unanswerable without further information, please let me know.

Jace J McPherson
  • 450
  • 3
  • 13

1 Answers1

3

Change the layout_height from wrap_content to either match_parent or fill_parent.

This is explained very well by this answer.

Community
  • 1
  • 1
Andrew Breen
  • 685
  • 3
  • 11