user1163234
user1163234

Reputation: 2497

TextView Not appearing after listview

I want to display the TextView after the listview in my XML I am using a diffrent XML to fill in the elements of th elist view . I added another textview after(below the listview) the list view but I am cannot see it...When I tried to place the listview its own layout i got a nullpointer...any idea?

XML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
  <TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Large Text"
    android:textAppearance="?android:attr/textAppearanceLarge" />
<ListView
     android:id="@+id/listView1"
     android:layout_height="fill_parent"
     android:layout_width="fill_parent">

</ListView>
    <TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Large Text"
     />

Upvotes: 0

Views: 2629

Answers (4)

MH.
MH.

Reputation: 45493

As alternative for the RelativeLayout solution (and suggested by Mohamed):

....
<ListView
    android:id="@+id/listView1"
    android:layout_height="0dp"
    android:layout_width="fill_parent"
    android:layout_weight="1" />
....

Upvotes: 1

Mohamed Alothman
Mohamed Alothman

Reputation: 66

Using a relative layout would be best as jitendra suggested. Alternatively, I checked the layout myself and the second TextView field showed up when I assigned a weight to ListView

Upvotes: 0

jeet
jeet

Reputation: 29199

I think you should use RelativeLayout instead of LinearLayout with having listView above of Text view with fill parent height, and text view to align bottom of parent with wrap_content.

XML

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
  <TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Large Text"
    android:textAppearance="?android:attr/textAppearanceLarge" />
<ListView
     android:id="@+id/listView1"
     android:layout_above="@+id/textView2"
     android:layout_below="@+id/textView1"
     android:layout_height="fill_parent"
     android:layout_width="fill_parent">

</ListView>
    <TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Large Text"
    android:layout_alignParentBottom="true"
     />

</RelativeLayout>

Upvotes: 2

Paresh Mayani
Paresh Mayani

Reputation: 128428

Because you have declared height and width with fill_parent.

Just declare android:width="fill_parent" and android:height="wrap_content".

Once you make this change, your TextView will be there.

Upvotes: 1

Related Questions