3
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    style="@style/bag" 
    android:layout_height="fill_parent" android:layout_width="fill_parent"
    android:orientation="vertical" >

<RelativeLayout
        android:id="@+id/relativeLayout2"
            style="@style/relbag"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

        <TextView style="@style/CodeFont" 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content"
        android:layout_marginLeft="25dp"
        android:layout_marginTop="18dp"
        android:textSize="15dp"
        android:text="General Preference"
        android:id="@+id/genpref">
        </TextView>


    <ListView
        android:id="@+id/settingsListView1"
        style="@style/listbag"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="15dip"
        android:layout_marginRight="15dip"

        android:background="@drawable/radius"
        android:listSelector="@drawable/list_selector"
        android:paddingTop="8dip"
        android:paddingBottom="8dip" 
        android:scrollbars="none"
        android:layout_below="@id/genpref"/>

        <TextView style="@style/CodeFont" 
        android:id="@+id/notpref"
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content"
        android:layout_marginLeft="25dp"
        android:layout_marginTop="25dp"
        android:textSize="15dp"
        android:text="Notification Preference"
        android:layout_below="@id/settingsListView1">
        </TextView>


        <ListView style="@style/listbag" android:id="@+id/settingsListView2" android:layout_width="fill_parent"
         android:layout_height="fill_parent"
            android:layout_marginLeft="15dip" android:layout_marginRight="15dip" 
              android:layout_marginBottom="15dip" 
        android:background="@drawable/radius" 
                android:paddingLeft="5dip" android:paddingRight="5dip" 
            android:paddingTop="15dip" android:paddingBottom="15dip" 
            android:listSelector="@drawable/list_selector" 
            android:layout_below="@id/notpref" 
            android:scrollbars="none"
            />
            </RelativeLayout>
</LinearLayout>

enter image description here

In my app I want create two listview into linearlayout and make linearlayout scrollable not using ScrollView. As far as I read scrollview has a issues working with listview. This picture isn't exactly what I want but let's pretend there is another listview below of listview. So I want display listview's all available items (in my app 2 listview's items) and make LinearLayout scrollable. ScrollView doesn't go fine because it has to have only one direct child. I can't find solution. So please help me make solution, Thanks

2
  • I've seen other questions like this and don't understand why people want to display a ListView with all available list items showing. The whole point of a ListView (and its ability to scroll) is that it's meant to fit the screen (or part of it) and can be scrolled to show additional items which can't fit the space it occupies. If you want to show a sequence of 'items' just create a view for an item then create multiples of it dynamically inserting them into a ScrollView and forget about using ListView. Commented Nov 29, 2011 at 6:30
  • refer stackoverflow.com/a/17876855/336990 ...might be useful Commented Jul 26, 2013 at 8:46

4 Answers 4

7

I dont think its a good idea to put multiple lists in a single screen becoz touch will become weird and using screen will become complex.You should think something else to display multiple lists together in a single screen.You can horizontally arrange multiple lists in a single screen.Romain Guy(Google developer) is also accepting this fact in the following link....

http://groups.google.com/group/android-developers/browse_thread/thread/77acd4e54120b777

I hope this answer will help u to solve ur problem.

Sign up to request clarification or add additional context in comments.

Comments

0

Use a LinearLayout as a child to the ScrollView, and place the ListView as a child to the LinearLayout.

2 Comments

That aint gonna work bro, I tried this already. but thanks anyway for your advice
in that case, you can try this question: Multiple ListView issue
0

I thnk here is your solution,,

you do not need to use ScrollView in LinearLayout.

Use layout_weight param in childviews (In your case both listview) of your LinearLayout

As layout_weight param is not available in RelativeLayout you need to change it with LinearLayout.

you can make like following,

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    style="@style/bag" 
    android:layout_height="fill_parent" android:layout_width="fill_parent"
    android:orientation="vertical" >

<LinearLayout
        android:id="@+id/relativeLayout2"
            style="@style/relbag"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
    android:orientation="vertical">

        <TextView style="@style/CodeFont" 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content"
        android:layout_marginLeft="25dp"
        android:layout_marginTop="18dp"
        android:textSize="15dp"
        android:text="General Preference"
        android:id="@+id/genpref">
        </TextView>


    <ListView
        android:id="@+id/settingsListView1"
        style="@style/listbag"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:layout_marginLeft="15dip"
        android:layout_marginRight="15dip"
        android:background="@drawable/radius"
        android:listSelector="@drawable/list_selector"
        android:paddingTop="8dip"
        android:paddingBottom="8dip"/>

        <TextView style="@style/CodeFont" 
        android:id="@+id/notpref"
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content"
        android:layout_marginLeft="25dp"
        android:layout_marginTop="25dp"
        android:textSize="15dp"
        android:text="Notification Preference">
        </TextView>


        <ListView style="@style/listbag" 
        android:id="@+id/settingsListView2" 
        android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
                android:layout_marginLeft="15dip" 
        android:layout_marginRight="15dip" 
                android:layout_marginBottom="15dip" 
            android:background="@drawable/radius" 
                android:paddingLeft="5dip" android:paddingRight="5dip" 
                android:paddingTop="15dip" android:paddingBottom="15dip" 
                android:listSelector="@drawable/list_selector"/>

     </LinearLayout>
</LinearLayout>

Change your xml with above.. i had not tested so their may be some silly error of params that you can solve easily..

Comments

0

i used this and helped me

ListAdapter listAdapter = listView.getAdapter();
int rows = listAdapter.getCount();
int height = 60 * rows; // Insert the general cell height plus the dividers.

ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = height;
listView.setLayoutParams(params);
listView.requestLayout();

hope help u too

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.