user1855400
user1855400

Reputation: 21

Can't get RelativeLayout to work in Listview

I am having problems using a RelativeLayout in a ListView. I would like to have the two EditText fields one above the other, instead they completely overlap one another. I have more text to put in each row, so side by side isn't an option.

I tried taking out all extraneous code to make it work, so this is what I have:

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

<ListView android:id="@android:id/list" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />

</LinearLayout> 

Here is my relative layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <EditText
        android:id="@+id/time"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20sp" />


    <EditText
        android:id="@+id/room"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/time"
        android:textSize="20sp" />

</RelativeLayout>

Any help would be greatly appreciated. Thank you.

Upvotes: 2

Views: 118

Answers (3)

Vipul
Vipul

Reputation: 28093

Replace

android:layout_below="@id/subject"

With

android:layout_below="@+id/time"

So That EditText with id room will be below to EditText with id time.

Upvotes: 2

allsoft
allsoft

Reputation: 198

You need to replace android:layout_below="@id/subject" to android:layout_below="@+id/time"

Upvotes: 1

PravinCG
PravinCG

Reputation: 7708

Use LinearLayout for this use case

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical>

<EditText
    android:id="@+id/time"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="20sp" />


<EditText
    android:id="@+id/room"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="20sp" />

</LinearLayout>

Upvotes: 0

Related Questions