0

I have two listview. i need to scroll one listview as the continuation of another list view. In between the list there should be a text view. if i use the two listview and textview inside a scrollview icould not able to scroll both the list. if i use the listview without scrollview i can see the two listview but scrolling is not continues.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#FAF0BE" >



    <Button
        android:id="@+id/btnheader"
        android:layout_width="fill_parent"
        android:layout_height="40dp"
        android:background="#A1CAF1"
        android:text="DisoderDetail" />

    <TextView
        android:id="@+id/txtTmtDnam"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/btnheader"
        android:layout_marginLeft="@dimen/marginLLeft"
        android:layout_marginTop="@dimen/marginTopp"
        android:text="jgjggjh"
        android:textColor="#000000" />

    <TextView
        android:id="@+id/txtdisDdtail"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/txtTmtDnam"
        android:layout_marginLeft="@dimen/marginLLeft"
        android:layout_marginTop="@dimen/marginTopp"
        android:text="jgjggjh hjhhhjh jhjhh"
        android:textColor="#000000" />



    <RelativeLayout
        android:id="@+id/Rvlytt2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/lyt2"
        android:layout_below="@id/txtdisDdtail"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="@dimen/marginBottomm"
        android:layout_marginTop="@dimen/marginTop"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/starimg1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="5dp"
            android:layout_marginTop="10dp"
            android:onClick="star1Clicked"
            android:src="@drawable/starunselected"
            android:tag="1" />

        <ImageView
            android:id="@+id/starimg2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="5dp"
            android:layout_marginTop="10dp"
            android:layout_toRightOf="@+id/starimg1"
            android:onClick="star2Clicked"
            android:src="@drawable/starunselected"
            android:tag="2" />

        <ImageView
            android:id="@+id/starimg3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="5dp"
            android:layout_marginTop="10dp"
            android:layout_toRightOf="@+id/starimg2"
            android:onClick="star3Clicked"
            android:src="@drawable/starunselected"
            android:tag="3" />

        <ImageView
            android:id="@+id/starimg4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="5dp"
            android:layout_marginTop="10dp"
            android:layout_toRightOf="@+id/starimg3"
            android:onClick="star4Clicked"
            android:src="@drawable/starunselected"
            android:tag="4" />

   </RelativeLayout> 
        <ScrollView
            android:id="@+id/Scrlvw"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/Rvlytt2" >

    <RelativeLayout
        android:id="@+id/rvl1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/txtDcmt"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_marginTop="@dimen/marginTop"
            android:text="comment"
            android:textColor="#000000" />

        <ListView
            android:id="@+id/lstvwDis11"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/txtDcmt" >
        </ListView>
        </RelativeLayout>


        <RelativeLayout
        android:id="@+id/rvl2"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@id/rvl1"
        >

        <TextView
            android:id="@+id/txtDrate"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@id/lstvwDis11"
            android:layout_marginTop="@dimen/marginTop"
            android:text="Rate"
            android:textColor="#000000" />

        <ListView
            android:id="@+id/lstvwDis12"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/txtDrate" >
        </ListView>
    </RelativeLayout>


    </ScrollView>

    <RelativeLayout
        android:id="@+id/Rvlt22"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" >

        <EditText
            android:id="@+id/Edtcmmt"
            android:layout_width="250dp"
            android:layout_height="50dp"
            android:layout_marginLeft="5dp"
            android:background="#ffffff"
            android:hint="Add a comment"
            android:textColor="#000000" />

        <Button
            android:id="@+id/btnpost"
            android:layout_width="130dp"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/Edtcmmt"
            android:onClick="OnPostbtnclick"
            android:text="Post" />
    </RelativeLayout>

</RelativeLayout>
  • 3
    this is very very bad idea to put `listView` inside `scrollView` – Shayan Pourvatan Jun 24 '14 at 06:11
  • 1
    agree with @shayanpourvatan. You should review your design. – Lazy Ninja Jun 24 '14 at 06:12
  • what do you mean by continues, and list view in side scroll view is not good way of programming. Instead of set the height to the list view. – Sush Jun 24 '14 at 06:13
  • Please don't try to used any scroll container view inside any parent scroll container. – Haresh Chhelana Jun 24 '14 at 06:15
  • 1
    http://stackoverflow.com/questions/9587754/how-to-add-two-listview-in-scrollview http://stackoverflow.com/questions/6482173/two-listviews-scrollview try this bro. so that you can understand what they commented. – cjnahine05 Jun 24 '14 at 06:16
  • @sush i know its not good. but i have two 2 listviews first listview is for comment and 2nd for rating.ist listview should display all the comments and on continues scrolling 2nd listvw should also be required to scroll – user3667915 Jun 24 '14 at 06:19
  • @user3667915 set height for the list view – Sush Jun 24 '14 at 06:21
  • Like already been said by others: nesting scrollablew vies is not a wise idea. As an alternative layout, if you have the screenspace for it, is to put the two lists next to each other. Might be a solution for a landscape layout. Otherwise you might want use a `TabHost` related view in a portrait layout, where the user can decide which of the two to view. But this last alternative is only really an option if your two lists do not need to be seen at the same time. – Xilconic Jun 24 '14 at 06:27
  • Is there a reason you don't want to put comments and ratings in the same row? It is more user friendly IMO – Lazy Ninja Jun 24 '14 at 06:33

2 Answers2

2

This is not correct design for starters but if you want to stick with the design one quick fix that will make your code work is to put both of your listViews inside one more list view and put that under scroll view. that should solve your problem of scrolling.

dirtydexter
  • 1,063
  • 1
  • 10
  • 17
0

When placing ListView inside ScrollView I use the following method to set listView height and the scrolling works properly. Use this after you've added all views to your listview.

public static void setListViewHeightBasedOnChildren(ListView listView) {
              ListAdapter listAdapter = listView.getAdapter();
            if (listAdapter == null) {
            // pre-condition
                  return;
            }

            int totalHeight = listView.getPaddingTop() + listView.getPaddingBottom();
            for (int i = 0; i < listAdapter.getCount(); i++) {
                 View listItem = listAdapter.getView(i, null, listView);
                 if (listItem instanceof ViewGroup) {
                    listItem.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
                 }
                 listItem.measure(0, 0);
                 totalHeight += listItem.getMeasuredHeight();
            }

            ViewGroup.LayoutParams params = listView.getLayoutParams();
            params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
                      listView.setLayoutParams(params);
        }
}
Shivam Verma
  • 7,973
  • 3
  • 26
  • 34