Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

listview shows nothing and hide data

i want to show seven textviews and two buttons horizontally in list. My list works fine with five textviews if a add more controls then it does not show anything. my code is correct i tried to change everything in xml but i'm unable to see anything on screen. please help me how can i use it in correct format.

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

 <!-- Third header line and column headings -->
 <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="30dp"
    android:orientation="horizontal"
    android:background="#A1E9FF">

    <TextView android:id="@+id/column_header1"
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:layout_weight="1"
        />
    <TextView android:id="@+id/column_header2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        />
 </LinearLayout>  

 <ListView
    android:id="@+id/listView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    android:divider="#b5b5b5"
    android:dividerHeight="2dp">
</ListView>

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

 <TextView
    android:id="@+id/plan_date"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="21dp"
    android:layout_toRightOf="@+id/Plan_no"
    android:text="plan date "
    android:textColor="#000"
    android:textSize="15dp" />

 <TextView
    android:id="@+id/morn_even"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="31dp"
    android:layout_toRightOf="@+id/doc_code"
    android:text="morn_even"
    android:textColor="#000"
    android:textSize="15dp" />

 <Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_marginRight="12dp"
    android:layout_toLeftOf="@+id/button2"
    android:text="Visited"
    android:textColor="#000" />

<TextView
    android:id="@+id/ff_code"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="30dp"
    android:layout_toRightOf="@+id/morn_even"
    android:text="ff code"
    android:textColor="#000"
    android:textSize="15dp" />

<TextView
    android:id="@+id/speciality"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/ff_code"
    android:layout_marginLeft="22dp"
    android:layout_toRightOf="@+id/ff_code"
    android:text="speciality"
     android:textColor="#000"
    android:textSize="15dp"/>

<TextView
    android:id="@+id/mon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="30dp"
    android:layout_toRightOf="@+id/plan_date"
    android:text="mon"
    android:textColor="#000"
    android:textSize="15dp" />

<TextView
    android:id="@+id/Plan_no"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignTop="@+id/textView1"
    android:layout_marginLeft="17dp"
    android:text="plan no"
    android:textColor="#000"
    android:textSize="15dp" />

<TextView
    android:id="@+id/doc_code"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="26dp"
    android:layout_toRightOf="@+id/mon"
    android:text="doc_code"
    android:textColor="#000"
    android:textSize="15dp" />

<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignTop="@+id/textView1"
    android:text="Not Visited"
    android:textColor="#000" />

 </RelativeLayout>
like image 326
Andrain Avatar asked Feb 11 '23 01:02

Andrain


1 Answers

As Torque203 noted, the orientation attribute is not valid for a RelativeLayout.

Another reason your RelativeLayout has not worked as you intended is that order matters when you define the relative positions of your child views.
When a RelativeLayout is inflated the XML is read from top to bottom, and a new child view can only be specified as relative to other child views that have already been defined before it.

Consider your second TextView:

<TextView
    android:id="@+id/morn_even"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="31dp"
    android:layout_toRightOf="@+id/doc_code"
    android:text="morn_even"
    android:textColor="#000"
    android:textSize="15dp" />

You specify that this view is "toRightOf" the view doc_code, but the RelativeLayout doesn't know anything about this doc_code view yet, because you don't define it until near the end of the XML.

Your are not alone here though. A lot of people misunderstand this when they first start playing with RelativeLayout.

The key thing to understand is that a RelativeLayout will only implement relative position rules that are anchored to a view who's position is already defined and fixed.

For example consider a new empty RelativeLayout:

  • We add a new child view A to it.

For this first child, we can only specify position rules relative to it's parent.
If we don't define any position rules relative to it's parent, it will be placed in the top left corner by default.

  • We add a new child view B.

For this child we can specify position rules relative to it's parent or relative to the existing view A.
We cannot specify any position rules relative to view C which hasn't been defined yet.

In a real world example, say I was lining up people for a group photo and first I tell Jim to stand at the center of the shot. If I then say "Ok Anita, you stand to the right of Liz" you are either just going to look at me funny, or say "But I don't know where Liz is meant to be standing yet!".

like image 70
Sound Conception Avatar answered Feb 15 '23 10:02

Sound Conception