6

in my code there is four listview how do i make screen scrollable to show all data of all listview? not this code make listview scrollable i dont want listview scrolling want ScreenScrollable like this image

   <?xml version="1.0" encoding="UTF-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:background="#ffffff"
   android:orientation="vertical" >

    <RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/imagelogo2"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/test_button_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="5dp"
        android:paddingTop="20dp"
        android:src="@drawable/back" >
     </ImageView>

     <ImageView
        android:id="@+id/test_button_image2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:paddingLeft="5dp"
        android:paddingRight="15dp"
        android:paddingTop="15dp"
        android:src="@drawable/options1" />
     </RelativeLayout>

  <TextView
    android:id="@+id/ElemenrySchool"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/btnback"
    android:paddingBottom="10dp"
    android:paddingLeft="5dp"
    android:paddingTop="10dp"
    android:text="elementry"
    android:textSize="17dp" >
     </TextView>

  <LinearLayout
    android:id="@+id/lytContent"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:background="@drawable/border2"
    android:orientation="vertical"
    android:paddingLeft="10dp"
    android:paddingRight="10dp" >

    <ListView
        android:id="@+id/listMainMenu11"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:dividerHeight="1dip"
        android:fadeScrollbars="true"
        android:listSelector="@drawable/listview_selector" />
       </LinearLayout>

    <TextView
    android:id="@+id/MiddleSchool"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingBottom="10dp"
    android:paddingLeft="5dp"
    android:paddingTop="10dp"
    android:text="Middle"
    android:textSize="17dp" >
   </TextView>

   <LinearLayout
    android:id="@+id/lytContent2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:background="@drawable/border2"
    android:orientation="vertical"
    android:paddingLeft="10dp"
    android:paddingRight="10dp" >

    <ListView
        android:id="@+id/listMainMenu22"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:dividerHeight="1dip"
        android:fadeScrollbars="true"
        android:listSelector="@drawable/listview_selector" />
   </LinearLayout>

   <TextView
    android:id="@+id/HighSchool"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/btnback"
    android:paddingBottom="10dp"
    android:paddingLeft="5dp"
    android:paddingTop="10dp"
    android:text="HighSchool"
    android:textSize="17dp" >
   </TextView>

    <LinearLayout
    android:id="@+id/lytContent3"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:background="@drawable/border2"
    android:orientation="vertical"
    android:paddingLeft="10dp"
    android:paddingRight="10dp" >

      <ListView
        android:id="@+id/listMainMenu33"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:dividerHeight="1dip"
        android:fadeScrollbars="true"
        android:listSelector="@drawable/listview_selector" />
   </LinearLayout>

   <TextView
    android:id="@+id/AtipicalSchool"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/btnback"
    android:paddingBottom="10dp"
    android:paddingLeft="5dp"
    android:paddingTop="10dp"
    android:text="Atipical"
    android:textSize="17dp" >
   </TextView>

   <LinearLayout
    android:id="@+id/lytContent4"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:background="@drawable/border2"
    android:orientation="vertical"
    android:paddingLeft="10dp"
    android:paddingRight="10dp" >

    <ListView
        android:id="@+id/listMainMenu44"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:dividerHeight="1dip"
        android:fadeScrollbars="true"
        android:listSelector="@drawable/listview_selector" />
   </LinearLayout>

  </LinearLayout>
3
  • 1
    List View is itself scrollable. Putting it in a ScrollView could be a bad idea! stackoverflow.com/questions/6210895/…
    – Prachi
    Aug 21, 2013 at 9:23
  • i save data in adapter of listview listMainMenu.setAdapter(mma); Middleschoollist.setAdapter(mma); HighSchoollist.setAdapter(mma); Atipicalschoollist.setAdapter(mma); Aug 21, 2013 at 9:24
  • data is dynamic get from server so must show inlistview????? Aug 21, 2013 at 9:25

2 Answers 2

48

use this custom listview component inside scrollview.

package com.app.Settings;

import android.content.Context;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.ListView;

public class ExpandableHeightListView extends ListView
{

boolean expanded = false;

public ExpandableHeightListView(Context context)
{
    super(context);
}

public ExpandableHeightListView(Context context, AttributeSet attrs)
{
    super(context, attrs);
}

public ExpandableHeightListView(Context context, AttributeSet attrs,int defStyle)
{
    super(context, attrs, defStyle);
}

public boolean isExpanded()
{
    return expanded;
}

@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
    // HACK! TAKE THAT ANDROID!
    if (isExpanded())
    {
        // Calculate entire height by providing a very large height hint.
        // But do not use the highest 2 bits of this integer; those are
        // reserved for the MeasureSpec mode.
        int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);

        ViewGroup.LayoutParams params = getLayoutParams();
        params.height = getMeasuredHeight();
    }
    else
    {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
}

public void setExpanded(boolean expanded)
{
    this.expanded = expanded;
}
} 

HOW TO USE IN XML?

 <yourPackageName.ExpandableHeightListView
        android:id="@+id/expandableHeightlist1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"   
        android:cacheColorHint="#00000000"
        android:fadingEdge="none"
        android:focusable="false"
        android:scrollbars="none"
        >
    </yourPackageName.ExpandableHeightGridView>

and set

yourListView.setExpanded(true);

By using this custom component you can set multiple listview inside scrollview. i am using this custom component.

Enjoy :)

9
  • wait dont go ill reply u in 5 mins Aug 21, 2013 at 9:59
  • where i put this? in main.java file or in xml file?? Aug 21, 2013 at 10:16
  • is show error The method setExpanded(boolean) is undefined for the type Object Aug 21, 2013 at 10:20
  • im declair istview like this listMainMenu = (ListView) findViewById(R.id.listMainMenu11); it is correct??? Aug 21, 2013 at 10:21
  • 1
    I dug into Android source repo, and found ScrollView.measureChildWithMargins() forcing its child views to be minimal in height (link). So, this hack is really necessary if one want a nested AdapterView (e.g. ListView) to be fully expanded in height within a parent ScrollView. And this might also be true of a nested AdapterView within a parent AdapterView.
    – Shigerello
    Feb 16, 2014 at 15:20
3

Never use two listview inside Scrollview

Don't try to use listview , use a LinearLayout instead , if you have got a fixed number of views. As listview will have its own scroll and this won't be a good user experience too.

7
  • then how do i show dynamic data in fourlist view like screenshot?? Aug 21, 2013 at 9:25
  • but my problemis i wanna make screen same like this image imgur.com/kR6vlKX load dynamic data form server showin listview Aug 21, 2013 at 9:27
  • From your image it seems that you have 3 dynamic data sets with 3 differnt data that totals to 9 , So I would recomment in this case you should go by using a linearlayout for all the sets and inside these 3 linear layouts create 3 buttons and populate the data you have got.
    – Prateek
    Aug 21, 2013 at 9:27
  • no data will be dynamic may be is three may be is 4 may b is 5 is fetch from server Aug 21, 2013 at 9:29
  • Look you just can't have two scrolls working smoothly on one screen. In such a case you dynamically add Buttons to your layout based on the size of data you get from the server.
    – Prateek
    Aug 21, 2013 at 9:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.