1

I have layout i want to use a scroll view.Inside the scroll view there is i a listview that have fixed 9 item so i want that these 9 items should be shown on the complete page and rest of the parts come inside the scroll view .

MY XML File:

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

    <LinearLayout
        android:id="@+id/headerLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:background="@drawable/top_bg"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/back_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="5dp"
            android:onClick="goBack"
            android:src="@drawable/back_button" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="75dp"
            android:layout_marginTop="10dp"
            android:text="Traveller Details"
            android:textColor="@android:color/white" />
    </LinearLayout>
     <ScrollView 
        android:layout_width="match_parent"
        android:layout_height="0dp" 
        android:layout_gravity="center"
        android:layout_below="@+id/headerLayout"
        android:fillViewport="true">

        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
    <LinearLayout 
        android:id="@+id/tittleLayout"

        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:layout_marginTop="5dp"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/TittleTravellerDetails"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="5dp"
            android:gravity="left"
            android:text="Traveller Details" />

        <View
            android:layout_width="wrap_content"
            android:layout_height="2dip"
            android:layout_marginTop="2dp"
            android:background="#FF909090" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/passengerDetails"
        android:layout_below="@+id/tittleLayout"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:orientation="vertical">

        <Spinner
            android:id="@+id/Tittle"
            android:layout_width="290dp"
            android:layout_marginLeft="5dp"
            android:layout_marginTop="5dp"
            android:visibility="gone"
            android:layout_height="wrap_content"/>
        <EditText
            android:id="@+id/firstName"
            android:layout_width="290dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_marginTop="10dp"
            android:maxLines="1"
            android:hint="First Name" />

        <EditText
            android:id="@+id/LastName"
            android:layout_width="290dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_marginTop="10dp"
            android:maxLines="1"
            android:hint="Last Name" />

        <ListView
            android:id="@+id/passengerList"
            android:layout_width="290dp"
            android:layout_height="166dp"
            android:layout_marginLeft="5dp"
            android:layout_marginTop="10dp"
            android:visibility="gone"
            android:choiceMode="singleChoice" />

    </LinearLayout>

    <LinearLayout 
        android:id="@+id/ContactDetailsLayout"
        android:layout_below="@+id/passengerDetails"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:layout_marginTop="10dp"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/TittleContactDetails"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:gravity="left"
            android:text="ContactDetails" />

        <View
            android:layout_width="wrap_content"
            android:layout_height="2dip"
            android:layout_marginTop="2dp"
            android:background="#FF909090" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/mobileEmailDetails"
        android:layout_below="@+id/ContactDetailsLayout"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:orientation="vertical">

        <EditText
            android:id="@+id/mobileNumber"
            android:layout_width="290dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_marginTop="10dp"
            android:maxLength="10"
            android:maxLines="1"
            android:inputType="number"
            android:hint="Mobile No" />

        <TextView
            android:id="@+id/emailid"
            android:layout_width="284dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:layout_marginTop="10dp"
            android:hint="Email ID" />

    </LinearLayout>
    <LinearLayout 
        android:id="@+id/continueBooking"
        android:layout_below="@+id/mobileEmailDetails"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/continuebooking"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="30dp"
            android:src="@drawable/searchflight" />

    </LinearLayout>
    </LinearLayout>
    </ScrollView>
 </RelativeLayout>

When the Listview will appear inside the layout id :passengerDetails then the edit text and the spinner will not appear .Please help me to resolve the issue.suggest me what i have to do

Developer
  • 6,292
  • 19
  • 55
  • 115
  • 1
    you should never put listview under scorllview – Raghunandan Aug 23 '13 at 07:53
  • Are you not getting any exception, b'coz AFAIK `ScrollView` must have only one child,.. – CRUSADER Aug 23 '13 at 07:54
  • @Raghunandan but the requirement is something like i have to do this – Developer Aug 23 '13 at 08:13
  • @Gaurav listview scrolls by itself. so putting listview under scroll view does not make sense – Raghunandan Aug 23 '13 at 08:14
  • @Raghunandan if u have a device install clearTrip app in u r phone on take 9 pax for flight search on the booking hwo they are doing i have to do same thing – Developer Aug 23 '13 at 08:15
  • @Gaurav i don't know i don't have that app – Raghunandan Aug 23 '13 at 08:16
  • install that in u r device it will give the complete picture that i am saying i have to get the complete feature that they have given – Developer Aug 23 '13 at 08:17
  • @Gaurav why should i you should make your question clear rather than asking others to install a app on their device and check to make your question understand. Why not post a snap snot – Raghunandan Aug 23 '13 at 08:19
  • i have to set error on listview items .so i have read some where that we cannot access the textview that are not on the screen.so poosibly i have to make all the items on the screen this is my main problem – Developer Aug 23 '13 at 08:20
  • first show the textview then list – Pankaj Arora Aug 23 '13 at 08:21
  • @Raghunandan ListView component did not render element on position that are not on the screen. It is a lazy component that renders only what is on screen. So don't assume that getChildAt returns a non null view.so because of this i am unable to set error on the items .So that's why i tried this to use scroll view – Developer Aug 23 '13 at 08:22
  • @Gaurav you need the index of the item in listview and then based on that set error to textview. remember listview recycles views and your question is not related to your comment. your title says different to the question in the comment. – Raghunandan Aug 23 '13 at 08:24
  • i have all that but it is giving me null pointer exception on that part that is not on the screen – Developer Aug 23 '13 at 08:26
  • @Gaurav because lsitivew recycles views. – Raghunandan Aug 23 '13 at 08:27
  • this is what i have posted if u can help me thanks for u r kind help http://stackoverflow.com/questions/18395669/how-i-can-set-error-on-a-listview?noredirect=1#comment27019491_18395669 – Developer Aug 23 '13 at 08:28

3 Answers3

1

http://developer.android.com/reference/android/widget/ScrollView.html

Quoting from docs

You should never use a ScrollView with a ListView, because ListView takes care of its own vertical scrolling. Most importantly, doing this defeats all of the important optimizations in ListView for dealing with large lists, since it effectively forces the ListView to display its entire list of items to fill up the infinite container supplied by ScrollView.

You can add the your others views as headers and footers to listview.

To add footers

public void addFooterView (View v)

Added in API level 1
Add a fixed view to appear at the bottom of the list. If addFooterView is called more than once, the views will appear in the order they were added. Views added using this call can take focus if they want.

NOTE: Call this before calling setAdapter. This is so ListView can wrap the supplied cursor with one that will also account for header and footer views.

Parameters
v   The view to add.

To add headers

public void addHeaderView (View v)

Added in API level 1
Add a fixed view to appear at the top of the list. If addHeaderView is called more than once, the views will appear in the order they were added. Views added using this call can take focus if they want.

NOTE: Call this before calling setAdapter. This is so ListView can wrap the supplied cursor with one that will also account for header and footer views.

Parameters
v   The view to add.
Raghunandan
  • 132,755
  • 26
  • 225
  • 256
  • accepted u r answer .so how could i get my functionality that i want – Developer Aug 23 '13 at 08:16
  • @Gaurav you can add header and footers to listview din't you see my previous comment check the edited post. You should post a snap shot rather than ask others to install some other app to understand your question. If that's the case drop a mail to the developer of that app may be he will help you – Raghunandan Aug 23 '13 at 08:19
  • @Gaurav you are asking too many question in the comment section. if you have a doubt that is different to the one related here pls post a new question. This is leading to a discussion. if the answer helps accept and ask a new question with relevant details – Raghunandan Aug 23 '13 at 08:28
  • in the comment there is my question if u need more code i can update on it .i am stucked in this from last 3 days – Developer Aug 23 '13 at 08:31
0

It is not a good idea to place one scrollable in another one. You need to avoid such type of layouts construction. You might want to rethink your layout.

Eugene
  • 59,186
  • 91
  • 226
  • 333
  • i have to show 9 items in the listview and the hieght will be fill parent.some other ways to create same layout – Developer Aug 23 '13 at 08:14
0

It's just simple replace the above ScrollView with the following:

  <ScrollView
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:layout_below="@+id/headerLayout"
    android:layout_gravity="center"
    android:fillViewport="true" >
Exceptional
  • 2,994
  • 1
  • 18
  • 25