Srinivas Rampelli
Srinivas Rampelli

Reputation: 39

listviews inside scrollview showing only one list item ? how to display all list items

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <TextView
        android:id="@+id/section_one_header"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="18dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        android:singleLine="true"
        android:text="Summary"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#51556C"
        android:textSize="13sp"
        android:textStyle="bold" />

    <ListView
        android:id="@+id/section_list_view"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="5dp" >
    </ListView>

    <TextView
        android:id="@+id/section_two_header"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="18dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        android:singleLine="true"
        android:text="Data"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#51556C"
        android:textSize="13sp"
        android:textStyle="bold" >
    </TextView>

    <LinearLayout
        android:id="@+id/eve_det"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="5dp"
        android:background="@layout/style_evedetail"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/section_two_data"
            android:layout_width="fill_parent"
            android:layout_height="100dp"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp"
            android:scrollbars="vertical"
            android:textSize="10sp" >
        </TextView>

        <EditText
            android:id="@+id/section_two_edit_text"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp"
            android:focusableInTouchMode="true"
            android:imeActionId="@+id/done_button"
            android:imeActionLabel="done"
            android:singleLine="true" />
    </LinearLayout>

    <TextView
        android:id="@+id/section_three_header"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="18dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        android:text="Attachment"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#51556C"
        android:textSize="13sp"
        android:textStyle="bold" >
    </TextView>
    <ListView
        android:id="@+id/attachment_list_view"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="20dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp" />
</LinearLayout>

this is the code under scroll view. Here i need to display Header and corresponding ListView then TextView with Edit Text, then again header and ListView. Can any one help me how to show all the list items in Two list views or if any one has other idea help me.

Upvotes: 2

Views: 4224

Answers (1)

Arpit Garg
Arpit Garg

Reputation: 8546

Yes as the List view has default scroll able functionality . If you place a list-view inside the another scroll-able view (say a Scroll-view ). The list scroll will hamper.

To Avoid such thing , list view has the concepts of header and footer views.

You can add n number of header and footers to the list.

Below is a sample code snippet how to add header/footer by inflating any xml layout to it

LayoutInflater inflater = activity.getLayoutInflater();
LinearLayout listFooterView = (LinearLayout)inflater.inflate(
            R.layout.footer_layout, null);

list.addFooterView(listFooterView);


LinearLayout listHeaderView = (LinearLayout)inflater.inflate(
                R.layout.header_layout, null);

    list.addHeaderView(listHeaderView);

Upvotes: 2

Related Questions